From 58ce696e0a1f622c94c23fed7671ad4c0e32e31d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 30 Oct 2014 15:22:17 +0100 Subject: 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 (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp new file mode 100644 index 000000000..7a84593ba --- /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 000000000..7573a0bdc --- /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 000000000..6be745de0 --- /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 : -- cgit v1.2.3 From 0976c402e0e09c4fe9d7d7d6990535e693b16a58 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 30 Oct 2014 20:11:17 +0100 Subject: Fix a bug whith units pointed by suv (bzr r13645.1.2) --- src/live_effects/lpe-fillet-chamfer.cpp | 12 +++++++----- src/live_effects/parameter/filletchamferpointarray.cpp | 9 ++------- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f15bf9215..8a8f68d80 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -34,6 +34,7 @@ #include "ui/tool/selectable-control-point.h" #include "ui/tool/node.h" #include "ui/tools/node-tool.h" +#include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -172,9 +173,9 @@ void LPEFilletChamfer::toggleHide() for (std::vector::const_iterator point_it = filletChamferData.begin(); point_it != filletChamferData.end(); ++point_it) { if (hide_knots) { - result.push_back(Point((*point_it)[X], abs((*point_it)[Y]) * -1)); + result.push_back(Point((*point_it)[X], std::abs((*point_it)[Y]) * -1)); } else { - result.push_back(Point((*point_it)[X], abs((*point_it)[Y]))); + result.push_back(Point((*point_it)[X], std::abs((*point_it)[Y]))); } } fillet_chamfer_values.param_set_and_write_new_value(result); @@ -211,7 +212,8 @@ void LPEFilletChamfer::updateFillet() { double power = 0; if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), "px") * -1; + Inkscape::Util::Unit const *doc_units = inkscape_active_desktop()->namedview->doc_units; + power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), doc_units->abbr) * -1; } else { power = radius; } @@ -589,11 +591,11 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } int type = 0; if(path_it->closed() && last){ - type = abs(filletChamferData[counter - counterCurves][Y]); + type = std::abs(filletChamferData[counter - counterCurves][Y]); } else if (!path_it->closed() && last){ //0 } else { - type = abs(filletChamferData[counter + 1][Y]); + type = std::abs(filletChamferData[counter + 1][Y]); } if (type == 3 || type == 4) { if (type == 4) { diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp index e2b1aba61..db24a9735 100644 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ b/src/live_effects/parameter/filletchamferpointarray.cpp @@ -175,13 +175,8 @@ void FilletChamferPointArrayParam::recalculate_controlpoints_for_new_pwd2( last_pathv[counterPaths][counter - offset].initialPoint(), 0.1))) { if ( curve_it2 == curve_endit) { - if (last_pathv[counterPaths].size() < pathv[counterPaths].size()) { - offset = abs(last_pathv[counterPaths].size() - - pathv[counterPaths].size()); - } else if (last_pathv[counterPaths].size() > - pathv[counterPaths].size()) { - offset = (abs(last_pathv[counterPaths].size() - - pathv[counterPaths].size())) * -1; + if (last_pathv[counterPaths].size() != pathv[counterPaths].size()) { + offset = (last_pathv[counterPaths].size() - pathv[counterPaths].size()) * -1; } else { offset = 0; } -- cgit v1.2.3 From ab9fe994f320dfd929888e2f5d821b6968385694 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 7 Feb 2015 18:05:01 +0100 Subject: 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 (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 7a84593ba..ce3aa86f6 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 7573a0bdc..33289f4f0 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 000000000..3872cf718 --- /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 6be745de0..8e570db4c 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; -- cgit v1.2.3 From 86891a9e442c81435c6d197cb09b3dc210643bc0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 Feb 2015 16:40:25 +0100 Subject: starting whith pointwise (bzr r13645.1.7) --- src/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 (limited to 'src') diff --git a/src/2geom/Makefile_insert b/src/2geom/Makefile_insert index e77f413cb..2f23bc442 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 ce3aa86f6..cd7f7914f 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 33289f4f0..c0974f54c 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 3872cf718..a71306bc9 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 8e570db4c..a18b08f27 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 c8a02c810..e171e99e3 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -63,6 +63,7 @@ set(live_effects_SRC parameter/path-reference.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp + parameter/pointwise.cpp parameter/random.cpp parameter/text.cpp paramter/transformedpoint.cpp @@ -139,6 +140,7 @@ set(live_effects_SRC parameter/originalpatharray.h parameter/point.h parameter/powerstrokepointarray.h + parameter/pointwise.h parameter/random.h parameter/text.h parameter/togglebutton.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d2bdf2d8d..f4eb4f46e 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -13,23 +13,8 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/lpe-fillet-chamfer.h" - -#include <2geom/sbasis-to-bezier.h> -#include <2geom/svg-elliptical-arc.h> -#include <2geom/line.h> -#include "desktop.h" -#include "display/curve.h" -#include "helper/geom-nodetype.h" -#include "helper/geom-curves.h" -#include "helper/geom.h" - -#include "live_effects/parameter/filletchamferpointarray.h" - -// for programmatically updating knots -#include "ui/tools-switch.h" -#include +#include "live_effects/parameter/pointwise.h" // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -38,348 +23,23 @@ using namespace Geom; namespace Inkscape { namespace LivePathEffect { -static const Util::EnumData FilletMethodData[FM_END] = { - { FM_AUTO, N_("Auto"), "auto" }, - { FM_ARC, N_("Force arc"), "arc" }, - { FM_BEZIER, N_("Force bezier"), "bezier" } -}; -static const Util::EnumDataConverter -FMConverter(FilletMethodData, FM_END); - -const double tolerance = 0.001; -const double gapHelper = 0.00001; - LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - fillet_chamfer_values(_("Fillet point"), _("Fillet point"), "fillet_chamfer_values", &wr, this), - hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), - ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), - only_selected(_("Change only selected nodes"), _("Change only selected nodes"), "only_selected", &wr, this, false), - flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), - use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), - unit(_("Unit:"), _("Unit"), "unit", &wr, this), - method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), - radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), - chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 0), - - helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0) + pointwise_values(_("Fillet point"), _("Fillet point"), "pointwise_values", &wr, this) { - registerParameter(&fillet_chamfer_values); - registerParameter(&unit); - registerParameter(&method); - registerParameter(&radius); - registerParameter(&chamfer_steps); - registerParameter(&helper_size); - registerParameter(&flexible); - registerParameter(&use_knot_distance); - registerParameter(&ignore_radius_0); - registerParameter(&only_selected); - registerParameter(&hide_knots); - - radius.param_set_range(0., infinity()); - radius.param_set_increments(1, 1); - radius.param_set_digits(4); - chamfer_steps.param_set_range(1, 999); - chamfer_steps.param_set_increments(1, 1); - chamfer_steps.param_set_digits(0); - helper_size.param_set_range(0, infinity()); - helper_size.param_set_increments(5, 5); - helper_size.param_set_digits(0); - fillet_chamfer_values.set_chamfer_steps(3); + registerParameter(&pointwise_values); } LPEFilletChamfer::~LPEFilletChamfer() {} -Gtk::Widget *LPEFilletChamfer::newWidget() -{ - // use manage here, because after deletion of Effect object, others might - // still be pointing to this widget. - Gtk::VBox *vbox = Gtk::manage(new Gtk::VBox(Effect::newWidget())); - - vbox->set_border_width(5); - vbox->set_homogeneous(false); - vbox->set_spacing(2); - std::vector::iterator it = param_vector.begin(); - while (it != param_vector.end()) { - if ((*it)->widget_is_visible) { - Parameter *param = *it; - Gtk::Widget *widg = param->param_newWidget(); - if (param->param_key == "radius") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateFillet)); - widg = widgRegistered; - if (widg) { - Gtk::HBox *scalarParameter = dynamic_cast(widg); - std::vector childList = scalarParameter->get_children(); - Gtk::Entry *entryWidg = dynamic_cast(childList[1]); - entryWidg->set_width_chars(6); - } - } else if (param->param_key == "chamfer_steps") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamferSubdivisions)); - widg = widgRegistered; - if (widg) { - Gtk::HBox *scalarParameter = dynamic_cast(widg); - std::vector childList = scalarParameter->get_children(); - Gtk::Entry *entryWidg = dynamic_cast(childList[1]); - entryWidg->set_width_chars(3); - } - } else if (param->param_key == "flexible") { - Gtk::CheckButton *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::toggleFlexFixed)); - } else if (param->param_key == "helper_size") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); - } else if (param->param_key == "hide_knots") { - Gtk::CheckButton *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::toggleHide)); - } else if (param->param_key == "only_selected") { - Gtk::manage(widg); - } else if (param->param_key == "ignore_radius_0") { - Gtk::manage(widg); - } - - Glib::ustring *tip = param->param_getTooltip(); - if (widg) { - vbox->pack_start(*widg, true, true, 2); - if (tip) { - widg->set_tooltip_text(*tip); - } else { - widg->set_tooltip_text(""); - widg->set_has_tooltip(false); - } - } - } - - ++it; - } - Gtk::HBox *filletContainer = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *fillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); - fillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::fillet)); - - filletContainer->pack_start(*fillet, true, true, 2); - Gtk::Button *inverseFillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); - inverseFillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseFillet)); - filletContainer->pack_start(*inverseFillet, true, true, 2); - - Gtk::HBox *chamferContainer = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *chamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); - chamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamfer)); - - chamferContainer->pack_start(*chamfer, true, true, 2); - Gtk::Button *inverseChamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); - inverseChamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseChamfer)); - chamferContainer->pack_start(*inverseChamfer, true, true, 2); - - vbox->pack_start(*filletContainer, true, true, 2); - vbox->pack_start(*chamferContainer, true, true, 2); - - return vbox; -} - -void LPEFilletChamfer::toggleHide() -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - for (std::vector::const_iterator point_it = filletChamferData.begin(); - point_it != filletChamferData.end(); ++point_it) { - if (hide_knots) { - result.push_back(Point((*point_it)[X], std::abs((*point_it)[Y]) * -1)); - } else { - result.push_back(Point((*point_it)[X], std::abs((*point_it)[Y]))); - } - } - fillet_chamfer_values.param_set_and_write_new_value(result); - refreshKnots(); -} - -void LPEFilletChamfer::toggleFlexFixed() -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - unsigned int i = 0; - for (std::vector::const_iterator point_it = filletChamferData.begin(); - point_it != filletChamferData.end(); ++point_it) { - if (flexible) { - result.push_back(Point(fillet_chamfer_values.to_time(i, (*point_it)[X]), - (*point_it)[Y])); - } else { - result.push_back(Point(fillet_chamfer_values.to_len(i, (*point_it)[X]), - (*point_it)[Y])); - } - i++; - } - if (flexible) { - radius.param_set_range(0., 100); - radius.param_set_value(0); - } else { - radius.param_set_range(0., infinity()); - radius.param_set_value(0); - } - fillet_chamfer_values.param_set_and_write_new_value(result); -} - -void LPEFilletChamfer::updateFillet() -{ - double power = 0; - if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), *defaultUnit) * -1; - } else { - power = radius; - } - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doUpdateFillet(path_from_piecewise(pwd2, tolerance), power); -} - -void LPEFilletChamfer::fillet() -{ - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), 1); -} - -void LPEFilletChamfer::inverseFillet() -{ - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), 2); -} - -void LPEFilletChamfer::chamferSubdivisions() -{ - fillet_chamfer_values.set_chamfer_steps(chamfer_steps); - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), chamfer_steps + 5000); -} - -void LPEFilletChamfer::chamfer() -{ - fillet_chamfer_values.set_chamfer_steps(chamfer_steps); - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), chamfer_steps + 3000); -} - -void LPEFilletChamfer::inverseChamfer() -{ - fillet_chamfer_values.set_chamfer_steps(chamfer_steps); - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doChangeType(path_from_piecewise(pwd2, tolerance), chamfer_steps + 4000); -} - -void LPEFilletChamfer::refreshKnots() -{ - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - fillet_chamfer_values.recalculate_knots(pwd2); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (tools_isactive(desktop, TOOLS_NODES)) { - tools_switch(desktop, TOOLS_SELECT); - tools_switch(desktop, TOOLS_NODES); - } -} - -void LPEFilletChamfer::doUpdateFillet(std::vector const& original_pathv, double power) -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - std::vector original_pathv_processed = pathv_to_linear_and_cubic_beziers(original_pathv); - int counter = 0; - for (PathVector::const_iterator path_it = original_pathv_processed.begin(); - path_it != original_pathv_processed.end(); ++path_it) { - if (path_it->empty()) - continue; - - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed() && path_it->back_closed().isDegenerate()) { - const Curve &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - double powerend = 0; - while (curve_it1 != curve_endit) { - powerend = power; - if (power < 0 && !use_knot_distance) { - powerend = fillet_chamfer_values.rad_to_len(counter,powerend); - } - if (power > 0) { - powerend = counter + (power / 100); - } - if (ignore_radius_0 && (filletChamferData[counter][X] == 0 || - filletChamferData[counter][X] == counter)) { - powerend = filletChamferData[counter][X]; - } - if (filletChamferData[counter][Y] == 0) { - powerend = filletChamferData[counter][X]; - } - if (only_selected && !isNodePointSelected(curve_it1->initialPoint())) { - powerend = filletChamferData[counter][X]; - } - result.push_back(Point(powerend, filletChamferData[counter][Y])); - ++curve_it1; - ++curve_it2; - counter++; - } - } - fillet_chamfer_values.param_set_and_write_new_value(result); -} - -void LPEFilletChamfer::doChangeType(std::vector const& original_pathv, int type) -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - std::vector original_pathv_processed = pathv_to_linear_and_cubic_beziers(original_pathv); - int counter = 0; - for (PathVector::const_iterator path_it = original_pathv_processed.begin(); path_it != original_pathv_processed.end(); ++path_it) { - int pathCounter = 0; - if (path_it->empty()) - continue; - - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed() && path_it->back_closed().isDegenerate()) { - const Curve &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - while (curve_it1 != curve_endit) { - bool toggle = true; - if (filletChamferData[counter][Y] == 0 || - (ignore_radius_0 && (filletChamferData[counter][X] == 0 || - filletChamferData[counter][X] == counter)) || - (only_selected && !isNodePointSelected(curve_it1->initialPoint()))) { - toggle = false; - } - if (toggle) { - if(type >= 5000){ - if(filletChamferData[counter][Y] >= 3000 && filletChamferData[counter][Y] < 4000){ - type = type - 2000; - } else if (filletChamferData[counter][Y] >= 4000 && filletChamferData[counter][Y] < 5000){ - type = type - 1000; - } - } - result.push_back(Point(filletChamferData[counter][X], type)); - } else { - result.push_back(filletChamferData[counter]); - } - ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } - counter++; - pathCounter++; - } - } - fillet_chamfer_values.param_set_and_write_new_value(result); -} void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) { - if (SP_IS_SHAPE(lpeItem)) { - std::vector point; - PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(SP_SHAPE(lpeItem)->_curve->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); + SPShape * shape = dynamic_cast(lpeItem); + if (shape) { + std::vector pointwise; + PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->gerCurve->get_pathvector()); + //Piecewise > pwd2_in = paths_to_pw(original_pathv); for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) continue; @@ -401,25 +61,16 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } int counter = 0; while (curve_it1 != curve_endit) { - std::pair positions = fillet_chamfer_values.get_positions(counter, original_pathv); + Geom::Saltellite sat(FILLET, true, true, false, false, false, 0, 0.2); + std::pair positions = pointwise_values.get_positions(counter, original_pathv); Geom::NodeType nodetype; if (positions.second == 0) { - if (path_it->closed()) { - Piecewise > u; - u.push_cut(0); - u.push(pwd2_in[fillet_chamfer_values.last_index(counter, original_pathv)], 1); - Geom::Curve const * A = path_from_piecewise(u, 0.1)[0][0].duplicate(); - nodetype = get_nodetype(*A, *curve_it1); - } else { - nodetype = NODE_NONE; - } + nodetype = NODE_NONE; } else { nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); } if (nodetype == NODE_CUSP) { - point.push_back(Point(0, 1)); - } else { - point.push_back(Point(0, 0)); + pointwise.push_back(std::pair); } ++curve_it1; if (curve_it2 != curve_endit) { @@ -428,222 +79,14 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) counter++; } } - fillet_chamfer_values.param_set_and_write_new_value(point); + pointwise_values.param_set_and_write_new_value(pointwise); } else { - g_warning("LPE Fillet can only be applied to shapes (not groups)."); + g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeItem); item->removeCurrentPathEffect(false); } } -void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) -{ - if (SP_IS_SHAPE(lpeItem)) { - if(hide_knots){ - fillet_chamfer_values.set_helper_size(0); - } else { - fillet_chamfer_values.set_helper_size(helper_size); - } - fillet_chamfer_values.set_document_unit(defaultUnit); - fillet_chamfer_values.set_use_distance(use_knot_distance); - fillet_chamfer_values.set_unit(unit.get_abbreviation()); - SPCurve *c = SP_IS_PATH(lpeItem) ? static_cast(lpeItem) - ->get_original_curve() - : SP_SHAPE(lpeItem)->getCurve(); - std::vector filletChamferData = fillet_chamfer_values.data(); - if (!filletChamferData.empty() && getKnotsNumber(c) != (int) - filletChamferData.size()) { - PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); - fillet_chamfer_values.recalculate_controlpoints_for_new_pwd2(pwd2_in); - } - } else { - g_warning("LPE Fillet can only be applied to shapes (not groups)."); - } -} - -int LPEFilletChamfer::getKnotsNumber(SPCurve const *c) -{ - int nKnots = c->nodes_in_path(); - PathVector const pv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - for (std::vector::const_iterator path_it = pv.begin(); - path_it != pv.end(); ++path_it) { - if (!(*path_it).closed()) { - nKnots--; - } - } - return nKnots; -} - -void -LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) -{ - if (!path_in.empty()) { - fillet_chamfer_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); - } -} - -std::vector -LPEFilletChamfer::doEffect_path(std::vector const &path_in) -{ - std::vector pathvector_out; - Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)); - pwd2_in = remove_short_cuts(pwd2_in, .01); - Piecewise > der = derivative(pwd2_in); - Piecewise > n = rot90(unitVector(der)); - fillet_chamfer_values.set_pwd2(pwd2_in, n); - std::vector filletChamferData = fillet_chamfer_values.data(); - unsigned int counter = 0; - const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); - for (PathVector::const_iterator path_it = path_in_processed.begin(); - path_it != path_in_processed.end(); ++path_it) { - if (path_it->empty()) - continue; - Geom::Path path_out; - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); - // the closing line segment is always of type - // Geom::LineSegment. - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - // closingline.isDegenerate() did not work, because it only checks for - // *exact* zero length, which goes wrong for relative coordinates and - // rounding errors... - // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); - } - } - unsigned int counterCurves = 0; - while (curve_it1 != curve_endit) { - Curve *curve_it2Fixed = (*path_it->begin()).duplicate(); - if(!path_it->closed() || curve_it2 != curve_endit){ - curve_it2Fixed = (*curve_it2).duplicate(); - } - bool last = curve_it2 == curve_endit; - std::vector times = fillet_chamfer_values.get_times(counter, path_in, last); - Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); - if (counterCurves > 0) { - knotCurve1->setInitial(path_out.finalPoint()); - } else { - path_out.start((*curve_it1).pointAt(times[0])); - } - Curve *knotCurve2 = curve_it2Fixed->portion(times[2], 1); - Point startArcPoint = knotCurve1->finalPoint(); - Point endArcPoint = curve_it2Fixed->pointAt(times[2]); - double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; - double k2 = distance(endArcPoint, curve_it1->finalPoint()) * K; - Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); - Ray ray1(startArcPoint, curve_it1->finalPoint()); - if (cubic1) { - ray1.setPoints((*cubic1)[2], startArcPoint); - } - Point handle1 = Point::polar(ray1.angle(),k1) + startArcPoint; - Geom::CubicBezier const *cubic2 = - dynamic_cast(&*knotCurve2); - Ray ray2(curve_it1->finalPoint(), endArcPoint); - if (cubic2) { - ray2.setPoints(endArcPoint, (*cubic2)[1]); - } - Point handle2 = endArcPoint - Point::polar(ray2.angle(),k2); - bool ccwToggle = cross(curve_it1->finalPoint() - startArcPoint, endArcPoint - startArcPoint) < 0; - double angle = angle_between(ray1, ray2, ccwToggle); - double handleAngle = ray1.angle() - angle; - if (ccwToggle) { - handleAngle = ray1.angle() + angle; - } - Point inverseHandle1 = Point::polar(handleAngle,k1) + startArcPoint; - handleAngle = ray2.angle() + angle; - if (ccwToggle) { - handleAngle = ray2.angle() - angle; - } - Point inverseHandle2 = endArcPoint - Point::polar(handleAngle,k2); - //straigth lines arc based - Line const x_line(Geom::Point(0,0),Geom::Point(1,0)); - Line const angled_line(startArcPoint,endArcPoint); - double angleArc = Geom::angle_between( x_line,angled_line); - double radius = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint))/sin(angle/2.0); - Coord rx = radius; - Coord ry = rx; - - if (times[1] != 1) { - if (times[1] != gapHelper && times[1] != times[0] + gapHelper) { - path_out.append(*knotCurve1); - } - int type = 0; - if(path_it->closed() && last){ - type = std::abs(filletChamferData[counter - counterCurves][Y]); - } else if (!path_it->closed() && last){ - //0 - } else { - type = std::abs(filletChamferData[counter + 1][Y]); - } - if(are_near(middle_point(startArcPoint,endArcPoint),curve_it1->finalPoint(), 0.0001)){ - path_out.appendNew(endArcPoint); - } else if (type >= 3000 && type < 4000) { - unsigned int chamferSubs = type-3000; - Geom::Path path_chamfer; - path_chamfer.start(path_out.finalPoint()); - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); - } else { - path_chamfer.appendNew(handle1, handle2, endArcPoint); - } - double chamfer_stepsTime = 1.0/chamferSubs; - for(unsigned int i = 1; i < chamferSubs; i++){ - Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); - path_out.appendNew(chamferStep); - } - path_out.appendNew(endArcPoint); - } else if (type >= 4000 && type < 5000) { - unsigned int chamferSubs = type-4000; - Geom::Path path_chamfer; - path_chamfer.start(path_out.finalPoint()); - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - ccwToggle = ccwToggle?0:1; - path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); - }else{ - path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); - } - double chamfer_stepsTime = 1.0/chamferSubs; - for(unsigned int i = 1; i < chamferSubs; i++){ - Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); - path_out.appendNew(chamferStep); - } - path_out.appendNew(endArcPoint); - } else if (type == 2) { - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - ccwToggle = ccwToggle?0:1; - path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); - }else{ - path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); - } - } else if (type == 1){ - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); - } else { - path_out.appendNew(handle1, handle2, endArcPoint); - } - } - } else { - path_out.append(*knotCurve1); - } - if (path_it->closed() && last) { - path_out.close(); - } - ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } - counter++; - counterCurves++; - } - pathvector_out.push_back(path_out); - } - return pathvector_out; -} }; //namespace LivePathEffect }; /* namespace Inkscape */ diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 0d6a1ff17..f4462d154 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -27,58 +27,23 @@ #include "live_effects/parameter/bool.h" #include "live_effects/parameter/unit.h" -#include "live_effects/parameter/filletchamferpointarray.h" +#include "live_effects/parameter/pointwise.h" #include "live_effects/effect.h" namespace Inkscape { namespace LivePathEffect { -enum FilletMethod { - FM_AUTO, - FM_ARC, - FM_BEZIER, - FM_END -}; class LPEFilletChamfer : public Effect { public: LPEFilletChamfer(LivePathEffectObject *lpeobject); virtual ~LPEFilletChamfer(); - virtual std::vector doEffect_path(std::vector const &path_in); - virtual void doOnApply(SPLPEItem const *lpeItem); - virtual void doBeforeEffect(SPLPEItem const *lpeItem); - virtual void adjustForNewPath(std::vector const &path_in); - virtual Gtk::Widget* newWidget(); - - int getKnotsNumber(SPCurve const *c); - void toggleHide(); - void toggleFlexFixed(); - void chamfer(); - void chamferSubdivisions(); - void inverseChamfer(); - void fillet(); - void inverseFillet(); - void updateFillet(); - void doUpdateFillet(std::vector const& original_pathv, double power); - void doChangeType(std::vector const& original_pathv, int type); - void refreshKnots(); - - FilletChamferPointArrayParam fillet_chamfer_values; -private: + PointwiseArrayParam pointwise_values; - BoolParam hide_knots; - BoolParam ignore_radius_0; - BoolParam only_selected; - BoolParam flexible; - BoolParam use_knot_distance; - UnitParam unit; - EnumParam method; - ScalarParam radius; - ScalarParam chamfer_steps; - ScalarParam helper_size; +private: LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index f990f41c7..d78b1e22f 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -26,6 +26,8 @@ ink_common_sources += \ live_effects/parameter/powerstrokepointarray.h \ live_effects/parameter/filletchamferpointarray.cpp \ live_effects/parameter/filletchamferpointarray.h \ + live_effects/parameter/pointwise.cpp \ + live_effects/parameter/pointwise.h \ live_effects/parameter/text.cpp \ live_effects/parameter/text.h \ live_effects/parameter/transformedpoint.cpp \ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 1b8f742da..bd2bf1870 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -48,6 +48,38 @@ ArrayParam::readsvg(const gchar * str) } return Geom::Point(Geom::infinity(),Geom::infinity()); } +void +sp_svg_satellite_read_d(gchar const *str, satellite *sat){ + gchar ** strarray = g_strsplit(str, "*", 0); + if(strarray.size() != 6){ + g_strfreev (strarray); + return NULL; + } + sat->setSatelliteType(SatelliteTypeMap[strarray[0]]); + sat->setActive(helperfns_read_bool(strarray[1], true)); + sat->sethasMirror(helperfns_read_bool(strarray[2], false)); + sat->setHidden(helperfns_read_bool(strarray[3], false)); + sat->setHidden(helperfns_read_bool(strarray[3], false)); + sat->setTime(sp_svg_number_read_d(strarray[4], 0.0)); + sat->setSize(sp_svg_number_read_d(strarray[5], 0.0)); + g_strfreev (strarray); +} + +template <> +std::pair +ArrayParam::readsvg(const gchar * str) +{ + gchar ** strarray = g_strsplit(str, ",", 2); + int index; + Geom::satellite sat = NULL; + unsigned int success = sp_svg_number_read_d(strarray[0], &index); + success += sp_svg_satellite_read_d(strarray[1], &sat); + g_strfreev (strarray); + if (success == 2) { + return std::pair; + } + return std::pair; +} } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index a600f0257..b93c7a617 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -93,7 +93,14 @@ protected: // separate items with pipe symbol str << " | "; } - str << vector[i]; + std::pair pointwiseElement = dynamic_cast ><(_vector[i]); + if(pointwiseElement){ + str << vector[i].first; + str << " , "; + str << vector[i].second; + } else { + str << vector[i]; + } } } diff --git a/src/live_effects/parameter/pointwise.cpp b/src/live_effects/parameter/pointwise.cpp new file mode 100644 index 000000000..ec83eb6c7 --- /dev/null +++ b/src/live_effects/parameter/pointwise.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "knotholder.h" + +// TODO due to internal breakage in glibmm headers, +// this has to be included last. +#include + + +using namespace Geom; + +namespace Inkscape { + +namespace LivePathEffect { + +PointwiseParam::PointwiseParam( + const Glib::ustring &label, const Glib::ustring &tip, + const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, + Effect *effect) + : ArrayParam(label, tip, key, wr, effect, 0) +{ + knot_shape = SP_KNOT_SHAPE_DIAMOND; + knot_mode = SP_KNOT_MODE_XOR; + knot_color = 0x00ff0000; +} + +PointwiseParam::~PointwiseParam() {} + +Gtk::Widget *PointwiseParam::param_newWidget() +{ + return NULL; +} + +void PointwiseParam::set_oncanvas_looks(SPKnotShapeType shape, + SPKnotModeType mode, + guint32 color) +{ + knot_shape = shape; + knot_mode = mode; + knot_color = color; +} + +PointwiseParamKnotHolderEntity:: +PointwiseParamKnotHolderEntity( + PointwiseParam *p) + : _pparam(p) {} + +void PointwiseParamKnotHolderEntity::knot_set(Point const &p, + Point const &/*origin*/, + guint state) +{ + Geom::Point const s = snap_knot_position(p, state); + _pparam->_vector.at(_index).second.setPosition(s,_pparam->_pointwise.pwd2[_pparam->_vector.at(_index).first]); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); +} + +Point PointwiseParamKnotHolderEntity::knot_get() const +{ + Geom::Point const canvas_point = _pparam->_vector.at(_index).second.getPosition(_pparam->_pointwise.pwd2[_pparam->_vector.at(_index).first]); + _pparam->updateCanvasIndicators(); + return canvas_point; +} + + +void PointwiseParam::addKnotHolderEntities(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item) +{ + for (unsigned int i = 0; i < _pointwise.satellites.size(); ++i) { + const gchar *tip; + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + PointwiseParamKnotHolderEntity *e = + new PointwiseParamKnotHolderEntity(this, i); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + knot_shape, knot_mode, knot_color); + knotholder->add(e); + } + updateCanvasIndicators(); +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/pointwise.h b/src/live_effects/parameter/pointwise.h new file mode 100644 index 000000000..59f1b4ff4 --- /dev/null +++ b/src/live_effects/parameter/pointwise.h @@ -0,0 +1,88 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_POINTWISE_H +#define INKSCAPE_LIVEPATHEFFECT_POINTWISE_H + +/* + * Inkscape::LivePathEffectParameters + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * To Nathan Hurst for his review and help on refactor + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * + * + * This parameter act as bridge from pointwise class to serialize it as a LPE + * parameter + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include "knot-holder-entity.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class PointwiseParamKnotHolderEntity; + +class PointwiseParam : public ArrayParam { +public: + PointwiseParam(const Glib::ustring &label, + const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, + Effect *effect); + virtual ~PointwiseParam(); + + virtual Gtk::Widget * param_newWidget() { + return NULL; + } + + void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, + guint32 color); + virtual bool providesKnotHolderEntities() const { + return true; + } + friend class PointwiseParamKnotHolderEntity; + +protected: + + StorageType readsvg(const gchar * str); + +private: + PointwiseParam(const PointwiseParam &); + PointwiseParam &operator=(const PointwiseParam &); + + SPKnotShapeType knot_shape; + SPKnotModeType knot_mode; + guint32 knot_color; +}; + +class PointwiseParamKnotHolderEntity : public KnotHolderEntity { +public: + PointwiseParamKnotHolderEntity(PointwiseParam *p, + unsigned int index); + virtual ~PointwiseParamKnotHolderEntity() {} + + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, + guint state); + virtual Geom::Point knot_get() const; + + /*Checks whether the index falls within the size of the parameter's vector*/ + bool valid_index(unsigned int index) const { + return (_pparam->_vector.size() > index); + } + ; + +private: + PointwiseParam *_pparam; + unsigned int _index; +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif -- cgit v1.2.3 From 99fb2239028e72f8773bff39e43f7af33b4252d4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 15 Feb 2015 19:29:48 +0100 Subject: first steps (bzr r13645.1.9) --- src/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 (limited to 'src') diff --git a/src/2geom/2geom.h b/src/2geom/2geom.h index 000f3423d..1deef9e8c 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 eeaecaa39..b49b78e7e 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 2f23bc442..8872065fb 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 cd7f7914f..5cbccbca9 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 c0974f54c..6e9c8840b 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 a71306bc9..474e98547 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 a18b08f27..8623ff1b0 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 e171e99e3..6b004e1df 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -63,7 +63,7 @@ set(live_effects_SRC parameter/path-reference.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp - parameter/pointwise.cpp + parameter/satellitepairarray.cpp parameter/random.cpp parameter/text.cpp paramter/transformedpoint.cpp @@ -140,7 +140,7 @@ set(live_effects_SRC parameter/originalpatharray.h parameter/point.h parameter/powerstrokepointarray.h - parameter/pointwise.h + parameter/satellitepairarray.h parameter/random.h parameter/text.h parameter/togglebutton.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f4eb4f46e..884e51ffd 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -14,20 +14,28 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/parameter/pointwise.h" +#include "live_effects/lpe-fillet-chamfer.h" +#include +#include <2geom/pointwise.h> +#include <2geom/satellite.h> +#include <2geom/satellite-enum.h> +#include "helper/geom-nodetype.h" +#include "helper/geom.h" +#include "display/curve.h" +#include // TODO due to internal breakage in glibmm headers, this must be last: #include -using namespace Geom; + namespace Inkscape { namespace LivePathEffect { LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - pointwise_values(_("Fillet point"), _("Fillet point"), "pointwise_values", &wr, this) + satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this) { - registerParameter(&pointwise_values); + registerParameter(&satellitepairarrayparam_values); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -35,12 +43,17 @@ LPEFilletChamfer::~LPEFilletChamfer() {} void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) { - SPShape * shape = dynamic_cast(lpeItem); + SPLPEItem * splpeitem = const_cast(lpeItem); + SPShape * shape = dynamic_cast(splpeitem); if (shape) { - std::vector pointwise; - PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->gerCurve->get_pathvector()); - //Piecewise > pwd2_in = paths_to_pw(original_pathv); - for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { + Geom::PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); + std::vector > satellites; + Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); + pwd2_in = remove_short_cuts(pwd2_in, .01); + Geom::Piecewise > der = derivative(pwd2_in); + Geom::Piecewise > n = rot90(unitVector(der)); + satellitepairarrayparam_values.set_pwd2(pwd2_in, n); + for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) continue; @@ -61,16 +74,15 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } int counter = 0; while (curve_it1 != curve_endit) { - Geom::Saltellite sat(FILLET, true, true, false, false, false, 0, 0.2); - std::pair positions = pointwise_values.get_positions(counter, original_pathv); + Geom::Satellite satellite(Geom::FILLET, true, true, false, false, 0.0, 0.2); Geom::NodeType nodetype; - if (positions.second == 0) { - nodetype = NODE_NONE; - } else { + if(counter!=0){ nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); + } else { + nodetype = Geom::NODE_NONE; } - if (nodetype == NODE_CUSP) { - pointwise.push_back(std::pair); + if (nodetype == Geom::NODE_CUSP) { + satellites.push_back(std::make_pair(counter, satellite)); } ++curve_it1; if (curve_it2 != curve_endit) { @@ -79,7 +91,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) counter++; } } - pointwise_values.param_set_and_write_new_value(pointwise); + satellitepairarrayparam_values.param_set_and_write_new_value(satellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeItem); @@ -87,6 +99,14 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } +void +LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) +{ + if (!path_in.empty()) { + //fillet_chamfer_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); + } +} + }; //namespace LivePathEffect }; /* namespace Inkscape */ diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index f4462d154..08000c0a5 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -15,19 +15,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#if defined(GLIBMM_DISABLE_DEPRECATED) && defined(HAVE_GLIBMM_THREADS_H) -# include -#endif - -#include "live_effects/parameter/enum.h" -#include "live_effects/parameter/bool.h" -#include "live_effects/parameter/unit.h" - -#include "live_effects/parameter/pointwise.h" +#include "2geom/pointwise.h" +#include "live_effects/parameter/satellitepairarray.h" #include "live_effects/effect.h" namespace Inkscape { @@ -40,8 +29,9 @@ public: virtual ~LPEFilletChamfer(); virtual void doOnApply(SPLPEItem const *lpeItem); + virtual void adjustForNewPath(std::vector const &path_in); - PointwiseArrayParam pointwise_values; + SatellitePairArrayParam satellitepairarrayparam_values; private: diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index d78b1e22f..33c6b0673 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -26,8 +26,8 @@ ink_common_sources += \ live_effects/parameter/powerstrokepointarray.h \ live_effects/parameter/filletchamferpointarray.cpp \ live_effects/parameter/filletchamferpointarray.h \ - live_effects/parameter/pointwise.cpp \ - live_effects/parameter/pointwise.h \ + live_effects/parameter/satellitepairarray.cpp \ + live_effects/parameter/satellitepairarray.h \ live_effects/parameter/text.cpp \ live_effects/parameter/text.h \ live_effects/parameter/transformedpoint.cpp \ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index bd2bf1870..d17f28c4f 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -6,8 +6,7 @@ #include "live_effects/parameter/array.h" -#include "svg/svg.h" -#include "svg/stringstream.h" +#include "helper-fns.h" #include <2geom/coord.h> #include <2geom/point.h> @@ -48,37 +47,47 @@ ArrayParam::readsvg(const gchar * str) } return Geom::Point(Geom::infinity(),Geom::infinity()); } -void -sp_svg_satellite_read_d(gchar const *str, satellite *sat){ - gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray.size() != 6){ +//TODO: move maybe to svg-lenght.cpp +unsigned int +sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ + if (!str) { + return 0; + } + gchar ** strarray = g_strsplit(str, " * ", 0); + if(strarray[6] && !strarray[7]){ + std::map< gchar const *, Geom::SatelliteType> gts = sat->GcharMapToSatelliteType; + sat->setSatelliteType(gts[strarray[0]]); + sat->setIsTime(helperfns_read_bool(strarray[1], true)); + sat->setActive(helperfns_read_bool(strarray[2], true)); + sat->setHasMirror(helperfns_read_bool(strarray[3], false)); + sat->setHidden(helperfns_read_bool(strarray[4], false)); + double time,size; + sp_svg_number_read_d(strarray[5], &time); + sp_svg_number_read_d(strarray[6], &size); + sat->setTime(time); + sat->setSize(size); g_strfreev (strarray); - return NULL; + return 1; } - sat->setSatelliteType(SatelliteTypeMap[strarray[0]]); - sat->setActive(helperfns_read_bool(strarray[1], true)); - sat->sethasMirror(helperfns_read_bool(strarray[2], false)); - sat->setHidden(helperfns_read_bool(strarray[3], false)); - sat->setHidden(helperfns_read_bool(strarray[3], false)); - sat->setTime(sp_svg_number_read_d(strarray[4], 0.0)); - sat->setSize(sp_svg_number_read_d(strarray[5], 0.0)); g_strfreev (strarray); + return 0; } template <> -std::pair -ArrayParam::readsvg(const gchar * str) +std::pair +ArrayParam >::readsvg(const gchar * str) { gchar ** strarray = g_strsplit(str, ",", 2); - int index; - Geom::satellite sat = NULL; - unsigned int success = sp_svg_number_read_d(strarray[0], &index); + double index; + std::pair result; + unsigned int success = (int)sp_svg_number_read_d(strarray[0], &index); + Geom::Satellite sat; success += sp_svg_satellite_read_d(strarray[1], &sat); g_strfreev (strarray); if (success == 2) { - return std::pair; + return std::make_pair(index, sat); } - return std::pair; + return std::make_pair((int)Geom::infinity(),sat); } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index b93c7a617..9f26ed3e6 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -15,6 +15,9 @@ #include "live_effects/parameter/parameter.h" +#include <2geom/satellite.h> +#include <2geom/satellite-enum.h> +#include <2geom/pointwise.h> #include "svg/svg.h" #include "svg/stringstream.h" @@ -93,16 +96,40 @@ protected: // separate items with pipe symbol str << " | "; } - std::pair pointwiseElement = dynamic_cast ><(_vector[i]); - if(pointwiseElement){ - str << vector[i].first; - str << " , "; - str << vector[i].second; - } else { - str << vector[i]; - } + writesvgData(str,vector[i]); } } + + void writesvgData(SVGOStringStream &str, float const &nVector) const { + str << nVector; + } + + void writesvgData(SVGOStringStream &str, double const &nVector) const { + str << nVector; + } + + void writesvgData(SVGOStringStream &str, Geom::Point const &nVector) const { + str << nVector; + } + + void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { + str << nVector.first; + str << " , "; + std::map stg = nVector.second.SatelliteTypeToGcharMap; + str << stg[nVector.second.satellitetype()]; + str << " * "; + str << nVector.second.isTime(); + str << " * "; + str << nVector.second.active(); + str << " * "; + str << nVector.second.hasMirror(); + str << " * "; + str << nVector.second.hidden(); + str << " * "; + str << nVector.second.size(); + str << " * "; + str < - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "knotholder.h" - -// TODO due to internal breakage in glibmm headers, -// this has to be included last. -#include - - -using namespace Geom; - -namespace Inkscape { - -namespace LivePathEffect { - -PointwiseParam::PointwiseParam( - const Glib::ustring &label, const Glib::ustring &tip, - const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, - Effect *effect) - : ArrayParam(label, tip, key, wr, effect, 0) -{ - knot_shape = SP_KNOT_SHAPE_DIAMOND; - knot_mode = SP_KNOT_MODE_XOR; - knot_color = 0x00ff0000; -} - -PointwiseParam::~PointwiseParam() {} - -Gtk::Widget *PointwiseParam::param_newWidget() -{ - return NULL; -} - -void PointwiseParam::set_oncanvas_looks(SPKnotShapeType shape, - SPKnotModeType mode, - guint32 color) -{ - knot_shape = shape; - knot_mode = mode; - knot_color = color; -} - -PointwiseParamKnotHolderEntity:: -PointwiseParamKnotHolderEntity( - PointwiseParam *p) - : _pparam(p) {} - -void PointwiseParamKnotHolderEntity::knot_set(Point const &p, - Point const &/*origin*/, - guint state) -{ - Geom::Point const s = snap_knot_position(p, state); - _pparam->_vector.at(_index).second.setPosition(s,_pparam->_pointwise.pwd2[_pparam->_vector.at(_index).first]); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); -} - -Point PointwiseParamKnotHolderEntity::knot_get() const -{ - Geom::Point const canvas_point = _pparam->_vector.at(_index).second.getPosition(_pparam->_pointwise.pwd2[_pparam->_vector.at(_index).first]); - _pparam->updateCanvasIndicators(); - return canvas_point; -} - - -void PointwiseParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item) -{ - for (unsigned int i = 0; i < _pointwise.satellites.size(); ++i) { - const gchar *tip; - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - PointwiseParamKnotHolderEntity *e = - new PointwiseParamKnotHolderEntity(this, i); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); - knotholder->add(e); - } - updateCanvasIndicators(); -} - -} /* namespace LivePathEffect */ - -} /* namespace Inkscape */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/pointwise.h b/src/live_effects/parameter/pointwise.h deleted file mode 100644 index 59f1b4ff4..000000000 --- a/src/live_effects/parameter/pointwise.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_POINTWISE_H -#define INKSCAPE_LIVEPATHEFFECT_POINTWISE_H - -/* - * Inkscape::LivePathEffectParameters - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * To Nathan Hurst for his review and help on refactor - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * - * - * This parameter act as bridge from pointwise class to serialize it as a LPE - * parameter - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include "knot-holder-entity.h" - -namespace Inkscape { - -namespace LivePathEffect { - -class PointwiseParamKnotHolderEntity; - -class PointwiseParam : public ArrayParam { -public: - PointwiseParam(const Glib::ustring &label, - const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, - Effect *effect); - virtual ~PointwiseParam(); - - virtual Gtk::Widget * param_newWidget() { - return NULL; - } - - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); - virtual bool providesKnotHolderEntities() const { - return true; - } - friend class PointwiseParamKnotHolderEntity; - -protected: - - StorageType readsvg(const gchar * str); - -private: - PointwiseParam(const PointwiseParam &); - PointwiseParam &operator=(const PointwiseParam &); - - SPKnotShapeType knot_shape; - SPKnotModeType knot_mode; - guint32 knot_color; -}; - -class PointwiseParamKnotHolderEntity : public KnotHolderEntity { -public: - PointwiseParamKnotHolderEntity(PointwiseParam *p, - unsigned int index); - virtual ~PointwiseParamKnotHolderEntity() {} - - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, - guint state); - virtual Geom::Point knot_get() const; - - /*Checks whether the index falls within the size of the parameter's vector*/ - bool valid_index(unsigned int index) const { - return (_pparam->_vector.size() > index); - } - ; - -private: - PointwiseParam *_pparam; - unsigned int _index; -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif -- cgit v1.2.3 From 3ff9b36f48101c62c460622dd683a582e5dc17ca Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 15 Feb 2015 19:31:04 +0100 Subject: first steps (bzr r13645.1.10) --- src/live_effects/parameter/satellitepairarray.cpp | 114 ++++++++++++++++++++++ src/live_effects/parameter/satellitepairarray.h | 95 ++++++++++++++++++ 2 files changed, 209 insertions(+) create mode 100644 src/live_effects/parameter/satellitepairarray.cpp create mode 100644 src/live_effects/parameter/satellitepairarray.h (limited to 'src') diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp new file mode 100644 index 000000000..f4f79b485 --- /dev/null +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -0,0 +1,114 @@ +/* + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "knotholder.h" +#include "live_effects/parameter/satellitepairarray.h" +#include "sp-lpe-item.h" +// TODO due to internal breakage in glibmm headers, +// this has to be included last. +#include + + +using namespace Geom; + +namespace Inkscape { + +namespace LivePathEffect { + +SatellitePairArrayParam::SatellitePairArrayParam( + const Glib::ustring &label, const Glib::ustring &tip, + const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, + Effect *effect) + : ArrayParam >(label, tip, key, wr, effect, 0) +{ + knot_shape = SP_KNOT_SHAPE_DIAMOND; + knot_mode = SP_KNOT_MODE_XOR; + knot_color = 0x00ff0000; +} + +SatellitePairArrayParam::~SatellitePairArrayParam() {} + +void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, + SPKnotModeType mode, + guint32 color) +{ + knot_shape = shape; + knot_mode = mode; + knot_color = color; +} + +void SatellitePairArrayParam::set_pwd2( + Piecewise > const &pwd2_in, + Piecewise > const &pwd2_normal_in) +{ + last_pwd2 = pwd2_in; + last_pwd2_normal = pwd2_normal_in; +} + +void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item) +{ + for (unsigned int i = 0; i < _vector.size(); ++i) { + const gchar *tip; + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + SatellitePairArrayParamKnotHolderEntity *e = + new SatellitePairArrayParamKnotHolderEntity(this, i); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + knot_shape, knot_mode, knot_color); + knotholder->add(e); + } +} + + +SatellitePairArrayParamKnotHolderEntity::SatellitePairArrayParamKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index) + : _pparam(p), + _index(index) +{ +} + + + +void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, + Point const &/*origin*/, + guint state) +{ + Geom::Point const s = snap_knot_position(p, state); + _pparam->_vector.at(_index).second.setPosition(s,_pparam->last_pwd2[_pparam->_vector.at(_index).first]); + SPLPEItem * splpeitem = dynamic_cast(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); + } +} + +Geom::Point +SatellitePairArrayParamKnotHolderEntity::knot_get() const +{ + Geom::Point const canvas_point = _pparam->_vector.at(_index).second.getPosition(_pparam->last_pwd2[_pparam->_vector.at(_index).second]); + return canvas_point; +} + + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h new file mode 100644 index 000000000..82d04c790 --- /dev/null +++ b/src/live_effects/parameter/satellitepairarray.h @@ -0,0 +1,95 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H +#define INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H + +/* + * Inkscape::LivePathEffectParameters + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * To Nathan Hurst for his review and help on refactor + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * + * + * This parameter act as bridge from pointwise class to serialize it as a LPE + * parameter + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include "live_effects/parameter/array.h" +#include "knot-holder-entity.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class SatellitePairArrayParamKnotHolderEntity; + +class SatellitePairArrayParam : public ArrayParam > { +public: + SatellitePairArrayParam(const Glib::ustring &label, + const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, + Effect *effect); + virtual ~SatellitePairArrayParam(); + + virtual Gtk::Widget * param_newWidget() { + return NULL; + } + + void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, + guint32 color); + virtual bool providesKnotHolderEntities() const { + return true; + } + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + void set_pwd2(Geom::Piecewise > const &pwd2_in, + Geom::Piecewise > const &pwd2_normal_in); + Geom::Piecewise > const &get_pwd2() const { + return last_pwd2; + } + Geom::Piecewise > const &get_pwd2_normal() const { + return last_pwd2_normal; + } + friend class SatellitePairArrayParamKnotHolderEntity; + +private: + SatellitePairArrayParam(const SatellitePairArrayParam &); + SatellitePairArrayParam &operator=(const SatellitePairArrayParam &); + + SPKnotShapeType knot_shape; + SPKnotModeType knot_mode; + guint32 knot_color; + + Geom::Piecewise > last_pwd2; + Geom::Piecewise > last_pwd2_normal; + +}; + +class SatellitePairArrayParamKnotHolderEntity : public KnotHolderEntity { +public: + SatellitePairArrayParamKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index); + virtual ~SatellitePairArrayParamKnotHolderEntity() {} + + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; + + /** Checks whether the index falls within the size of the parameter's vector */ + bool valid_index(unsigned int index) const { + return (_pparam->_vector.size() > index); + }; + +private: + SatellitePairArrayParam *_pparam; + unsigned int _index; +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif -- cgit v1.2.3 From 5c3350ef1281298f25c1cbcb60a66d238a417030 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 16 Feb 2015 00:12:00 +0100 Subject: added knots (bzr r13645.1.12) --- src/live_effects/lpe-fillet-chamfer.cpp | 20 +++++++++++--------- src/live_effects/parameter/array.cpp | 2 +- src/live_effects/parameter/array.h | 14 +++++++------- src/live_effects/parameter/satellitepairarray.cpp | 2 +- 4 files changed, 20 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 884e51ffd..5d6358bb2 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -54,11 +54,10 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Piecewise > n = rot90(unitVector(der)); satellitepairarrayparam_values.set_pwd2(pwd2_in, n); for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()) + if (path_it->empty()){ continue; - + } Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { const Geom::Curve &closingline = path_it->back_closed(); @@ -72,22 +71,25 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) curve_endit = path_it->end_open(); } } + Geom::Path::const_iterator curve_end = curve_endit; + --curve_end; int counter = 0; while (curve_it1 != curve_endit) { Geom::Satellite satellite(Geom::FILLET, true, true, false, false, 0.0, 0.2); Geom::NodeType nodetype; - if(counter!=0){ - nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); + if (counter==0) { + if (path_it->closed()) { + nodetype = Geom::get_nodetype(*curve_end, *curve_it1); + } else { + nodetype = Geom::NODE_NONE; + } } else { - nodetype = Geom::NODE_NONE; + nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); } if (nodetype == Geom::NODE_CUSP) { satellites.push_back(std::make_pair(counter, satellite)); } ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } counter++; } } diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index d17f28c4f..d1d718b08 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -53,7 +53,7 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ if (!str) { return 0; } - gchar ** strarray = g_strsplit(str, " * ", 0); + gchar ** strarray = g_strsplit(str, "*", 0); if(strarray[6] && !strarray[7]){ std::map< gchar const *, Geom::SatelliteType> gts = sat->GcharMapToSatelliteType; sat->setSatelliteType(gts[strarray[0]]); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 9f26ed3e6..ba1ed3d4e 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -114,20 +114,20 @@ protected: void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { str << nVector.first; - str << " , "; + str << ","; std::map stg = nVector.second.SatelliteTypeToGcharMap; str << stg[nVector.second.satellitetype()]; - str << " * "; + str << "*"; str << nVector.second.isTime(); - str << " * "; + str << "*"; str << nVector.second.active(); - str << " * "; + str << "*"; str << nVector.second.hasMirror(); - str << " * "; + str << "*"; str << nVector.second.hidden(); - str << " * "; + str << "*"; str << nVector.second.size(); - str << " * "; + str << "*"; str <_vector.at(_index).second.getPosition(_pparam->last_pwd2[_pparam->_vector.at(_index).second]); + Geom::Point const canvas_point = _pparam->_vector.at(_index).second.getPosition(_pparam->last_pwd2[_pparam->_vector.at(_index).first]); return canvas_point; } -- cgit v1.2.3 From 9593c78703845bfca18a3a135cbbc47cc03b54f6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 16 Feb 2015 21:49:53 +0100 Subject: continuing fillet/chamfer (bzr r13645.1.13) --- src/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 +- src/live_effects/parameter/satellitepairarray.cpp | 4 +- src/live_effects/parameter/satellitepairarray.h | 7 +- 7 files changed, 259 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 8623ff1b0..06b4a1dd6 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 5d6358bb2..df9de81b7 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -17,25 +17,38 @@ #include "live_effects/lpe-fillet-chamfer.h" #include +#include #include <2geom/pointwise.h> #include <2geom/satellite.h> #include <2geom/satellite-enum.h> +#include <2geom/svg-elliptical-arc.h> #include "helper/geom-nodetype.h" +#include "helper/geom-curves.h" #include "helper/geom.h" #include "display/curve.h" #include // TODO due to internal breakage in glibmm headers, this must be last: #include - +using namespace Geom; namespace Inkscape { namespace LivePathEffect { +static const Util::EnumData FilletMethodData[FM_END] = { + { FM_AUTO, N_("Auto"), "auto" }, + { FM_ARC, N_("Force arc"), "arc" }, + { FM_BEZIER, N_("Force bezier"), "bezier" } +}; +static const Util::EnumDataConverter +FMConverter(FilletMethodData, FM_END); + LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this) + satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this), + method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO) { registerParameter(&satellitepairarrayparam_values); + registerParameter(&method); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -46,23 +59,21 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPLPEItem * splpeitem = const_cast(lpeItem); SPShape * shape = dynamic_cast(splpeitem); if (shape) { - Geom::PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); - std::vector > satellites; - Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); + PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); + std::vector > satellites; + Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, .01); - Geom::Piecewise > der = derivative(pwd2_in); - Geom::Piecewise > n = rot90(unitVector(der)); - satellitepairarrayparam_values.set_pwd2(pwd2_in, n); - for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { + satellitepairarrayparam_values.set_pwd2(pwd2_in); + for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; } Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); + const Curve &closingline = path_it->back_closed(); // the closing line segment is always of type - // Geom::LineSegment. + // LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { // closingline.isDegenerate() did not work, because it only checks for // *exact* zero length, which goes wrong for relative coordinates and @@ -75,18 +86,18 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) --curve_end; int counter = 0; while (curve_it1 != curve_endit) { - Geom::Satellite satellite(Geom::FILLET, true, true, false, false, 0.0, 0.2); + Satellite satellite(FILLET, true, true, false, false, 0.0, 0.0); Geom::NodeType nodetype; if (counter==0) { if (path_it->closed()) { - nodetype = Geom::get_nodetype(*curve_end, *curve_it1); + nodetype = get_nodetype(*curve_end, *curve_it1); } else { - nodetype = Geom::NODE_NONE; + nodetype = NODE_NONE; } } else { nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); } - if (nodetype == Geom::NODE_CUSP) { + if (nodetype == NODE_CUSP) { satellites.push_back(std::make_pair(counter, satellite)); } ++curve_it1; @@ -101,11 +112,196 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } + +void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) +{ + SPLPEItem * splpeitem = const_cast(lpeItem); + SPShape * shape = dynamic_cast(splpeitem); + if (shape) { + SPCurve *c = shape->getCurve(); + SPPath * path = dynamic_cast(shape); + if(path){ + c = path->get_original_curve(); + } + PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); + Piecewise > pwd2_in = paths_to_pw(original_pathv); + pwd2_in = remove_short_cuts(pwd2_in, .01); + satellitepairarrayparam_values.set_pwd2(pwd2_in); + } else { + g_warning("LPE Fillet can only be applied to shapes (not groups)."); + } +} + +std::vector +LPEFilletChamfer::doEffect_path(std::vector const &path_in) +{ + std::vector pathvector_out; + Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)); + pwd2_in = remove_short_cuts(pwd2_in, .01); + satellitepairarrayparam_values.set_pwd2(pwd2_in); + std::vector > filletChamferData = satellitepairarrayparam_values.data(); + unsigned int counter = 0; + const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); + std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); + for (PathVector::const_iterator path_it = path_in_processed.begin(); + path_it != path_in_processed.end(); ++path_it) { + if (path_it->empty()) + continue; + Geom::Path path_out; + Geom::Path::const_iterator curve_it1 = path_it->begin(); + Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); + Geom::Path::const_iterator curve_endit = path_it->end_default(); + if (path_it->closed()) { + const Curve &closingline = path_it->back_closed(); + // the closing line segment is always of type + // LineSegment. + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + // closingline.isDegenerate() did not work, because it only checks for + // *exact* zero length, which goes wrong for relative coordinates and + // rounding errors... + // the closing line segment has zero-length. So stop before that one! + curve_endit = path_it->end_open(); + } + } + unsigned int counterCurves = 0; + while (curve_it1 != curve_endit) { + Curve *curve_it2Fixed = (*path_it->begin()).duplicate(); + int indexFix = 0; + if(!path_it->closed() || curve_it2 != curve_endit){ + curve_it2Fixed = (*curve_it2).duplicate(); + indexFix = counter; + } + bool last = curve_it2 == curve_endit; + std::vector times; + times.push_back(filletChamferData[counter].second.getTime()); + times.push_back(filletChamferData[indexFix].second.getOpositeTime((*curve_it1).toSBasis(),filletChamferData[indexFix].second.getTime())); + times.push_back(filletChamferData[indexFix].second.getTime()); + Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); + if (counterCurves > 0) { + knotCurve1->setInitial(path_out.finalPoint()); + } else { + path_out.start((*curve_it1).pointAt(times[0])); + } + Curve *knotCurve2 = curve_it2Fixed->portion(times[2], 1); + Point startArcPoint = knotCurve1->finalPoint(); + Point endArcPoint = curve_it2Fixed->pointAt(times[2]); + double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; + double k2 = distance(endArcPoint, curve_it1->finalPoint()) * K; + CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); + Ray ray1(startArcPoint, curve_it1->finalPoint()); + if (cubic1) { + ray1.setPoints((*cubic1)[2], startArcPoint); + } + Point handle1 = Point::polar(ray1.angle(),k1) + startArcPoint; + CubicBezier const *cubic2 = + dynamic_cast(&*knotCurve2); + Ray ray2(curve_it1->finalPoint(), endArcPoint); + if (cubic2) { + ray2.setPoints(endArcPoint, (*cubic2)[1]); + } + Point handle2 = endArcPoint - Point::polar(ray2.angle(),k2); + bool ccwToggle = cross(curve_it1->finalPoint() - startArcPoint, endArcPoint - startArcPoint) < 0; + double angle = angle_between(ray1, ray2, ccwToggle); + double handleAngle = ray1.angle() - angle; + if (ccwToggle) { + handleAngle = ray1.angle() + angle; + } + Point inverseHandle1 = Point::polar(handleAngle,k1) + startArcPoint; + handleAngle = ray2.angle() + angle; + if (ccwToggle) { + handleAngle = ray2.angle() - angle; + } + Point inverseHandle2 = endArcPoint - Point::polar(handleAngle,k2); + //straigth lines arc based + Line const x_line(Point(0,0),Point(1,0)); + Line const angled_line(startArcPoint,endArcPoint); + double angleArc = angle_between( x_line,angled_line); + double radius = distance(startArcPoint,middle_point(startArcPoint,endArcPoint))/sin(angle/2.0); + Coord rx = radius; + Coord ry = rx; + + if (times[1] != 1) { + if (times[1] != times[0]) { + path_out.append(*knotCurve1); + } + SatelliteType satType = FILLET; + if(path_it->closed() && last){ + satType = filletChamferData[counter - counterCurves].second.getSatelliteType(); + } else if (!path_it->closed() && last){ + //0 + } else { + satType = filletChamferData[counter + 1].second.getSatelliteType(); + } + if(are_near(middle_point(startArcPoint,endArcPoint),curve_it1->finalPoint(), 0.0001)){ + path_out.appendNew(endArcPoint); + } else if (satType == CHAMFER) { + unsigned int chamferSubs = 0; + Geom::Path path_chamfer; + path_chamfer.start(path_out.finalPoint()); + if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ + path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + } else { + path_chamfer.appendNew(handle1, handle2, endArcPoint); + } + double chamfer_stepsTime = 1.0/chamferSubs; + for(unsigned int i = 1; i < chamferSubs; i++){ + Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); + path_out.appendNew(chamferStep); + } + path_out.appendNew(endArcPoint); + } else if (satType == INVERSE_CHAMFER) { + unsigned int chamferSubs = 2; + Geom::Path path_chamfer; + path_chamfer.start(path_out.finalPoint()); + if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ + ccwToggle = ccwToggle?0:1; + path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + }else{ + path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + } + double chamfer_stepsTime = 1.0/chamferSubs; + for(unsigned int i = 1; i < chamferSubs; i++){ + Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); + path_out.appendNew(chamferStep); + } + path_out.appendNew(endArcPoint); + } else if (satType == INVERSE_FILLET) { + if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ + ccwToggle = ccwToggle?0:1; + path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + }else{ + path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + } + } else if (satType == FILLET){ + if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ + path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + } else { + path_out.appendNew(handle1, handle2, endArcPoint); + } + } + } else { + path_out.append(*knotCurve1); + } + if (path_it->closed() && last) { + path_out.close(); + } + ++curve_it1; + if (curve_it2 != curve_endit) { + ++curve_it2; + } + counter++; + counterCurves++; + } + pathvector_out.push_back(path_out); + } + return pathvector_out; +} + void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty()) { - //fillet_chamfer_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); + //satellitepairarrayparam_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); } } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 08000c0a5..94a2bd2b3 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -14,27 +14,35 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - +#include "live_effects/parameter/enum.h" #include "2geom/pointwise.h" #include "live_effects/parameter/satellitepairarray.h" #include "live_effects/effect.h" +using namespace Geom; namespace Inkscape { namespace LivePathEffect { +enum FilletMethod { + FM_AUTO, + FM_ARC, + FM_BEZIER, + FM_END +}; class LPEFilletChamfer : public Effect { public: LPEFilletChamfer(LivePathEffectObject *lpeobject); virtual ~LPEFilletChamfer(); - + virtual void doBeforeEffect(SPLPEItem const *lpeItem); + virtual std::vector doEffect_path(std::vector const &path_in); virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector const &path_in); SatellitePairArrayParam satellitepairarrayparam_values; private: - + EnumParam method; LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index d1d718b08..473b561d2 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -55,17 +55,16 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ } gchar ** strarray = g_strsplit(str, "*", 0); if(strarray[6] && !strarray[7]){ - std::map< gchar const *, Geom::SatelliteType> gts = sat->GcharMapToSatelliteType; - sat->setSatelliteType(gts[strarray[0]]); + sat->setSatelliteType(strarray[0]); sat->setIsTime(helperfns_read_bool(strarray[1], true)); sat->setActive(helperfns_read_bool(strarray[2], true)); sat->setHasMirror(helperfns_read_bool(strarray[3], false)); sat->setHidden(helperfns_read_bool(strarray[4], false)); double time,size; - sp_svg_number_read_d(strarray[5], &time); - sp_svg_number_read_d(strarray[6], &size); - sat->setTime(time); + sp_svg_number_read_d(strarray[5], &size); + sp_svg_number_read_d(strarray[6], &time); sat->setSize(size); + sat->setTime(time); g_strfreev (strarray); return 1; } diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index ba1ed3d4e..c99777b08 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -116,19 +116,19 @@ protected: str << nVector.first; str << ","; std::map stg = nVector.second.SatelliteTypeToGcharMap; - str << stg[nVector.second.satellitetype()]; + str << nVector.second.getSatelliteTypeGchar(); str << "*"; - str << nVector.second.isTime(); + str << nVector.second.getIsTime(); str << "*"; - str << nVector.second.active(); + str << nVector.second.getActive(); str << "*"; - str << nVector.second.hasMirror(); + str << nVector.second.getHasMirror(); str << "*"; - str << nVector.second.hidden(); + str << nVector.second.getHidden(); str << "*"; - str << nVector.second.size(); + str << nVector.second.getSize(); str << "*"; - str < > const &pwd2_in, - Piecewise > const &pwd2_normal_in) + Piecewise > const &pwd2_in) { last_pwd2 = pwd2_in; - last_pwd2_normal = pwd2_normal_in; } void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index 82d04c790..ff1924829 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -47,14 +47,10 @@ public: return true; } virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - void set_pwd2(Geom::Piecewise > const &pwd2_in, - Geom::Piecewise > const &pwd2_normal_in); + void set_pwd2(Geom::Piecewise > const &pwd2_in); Geom::Piecewise > const &get_pwd2() const { return last_pwd2; } - Geom::Piecewise > const &get_pwd2_normal() const { - return last_pwd2_normal; - } friend class SatellitePairArrayParamKnotHolderEntity; private: @@ -66,7 +62,6 @@ private: guint32 knot_color; Geom::Piecewise > last_pwd2; - Geom::Piecewise > last_pwd2_normal; }; -- cgit v1.2.3 From e6e262b34c193502d1f9be44324515bf8c861d47 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 17 Feb 2015 00:23:51 +0100 Subject: starting fillet/chamfer (bzr r13645.1.15) --- src/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(-) (limited to 'src') diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 06b4a1dd6..a83de5af2 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 df9de81b7..b34cd87a1 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -174,7 +174,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) bool last = curve_it2 == curve_endit; std::vector times; times.push_back(filletChamferData[counter].second.getTime()); - times.push_back(filletChamferData[indexFix].second.getOpositeTime((*curve_it1).toSBasis(),filletChamferData[indexFix].second.getTime())); + times.push_back(filletChamferData[indexFix].second.getOpositeTime((*curve_it1).toSBasis())); times.push_back(filletChamferData[indexFix].second.getTime()); Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); if (counterCurves > 0) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 94a2bd2b3..2c0dfcaab 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -19,7 +19,6 @@ #include "live_effects/parameter/satellitepairarray.h" #include "live_effects/effect.h" -using namespace Geom; namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index c99777b08..8145d62a3 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -115,7 +115,6 @@ protected: void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { str << nVector.first; str << ","; - std::map stg = nVector.second.SatelliteTypeToGcharMap; str << nVector.second.getSatelliteTypeGchar(); str << "*"; str << nVector.second.getIsTime(); -- cgit v1.2.3 From a230b9d6684f01ded46fd530ba0cc74ce9696e2d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 19 Feb 2015 21:53:20 +0100 Subject: Basic filleting using pointwise (bzr r13645.1.16) --- src/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 --- src/ui/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 (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 5cbccbca9..d7d5afc63 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 6e9c8840b..d48321832 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 000000000..b8ddd040b --- /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 6b004e1df..3af27a220 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -55,7 +55,6 @@ set(live_effects_SRC parameter/array.cpp parameter/bool.cpp - parameter/filletchamferpointarray.cpp parameter/parameter.cpp parameter/path.cpp parameter/originalpath.cpp @@ -131,7 +130,6 @@ set(live_effects_SRC parameter/array.h parameter/bool.h - parameter/filletchamferpointarray.h parameter/enum.h parameter/parameter.h parameter/path-reference.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index b34cd87a1..3b1b1697c 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -64,6 +64,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, .01); satellitepairarrayparam_values.set_pwd2(pwd2_in); + int counterTotal = 0; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; @@ -98,10 +99,11 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); } if (nodetype == NODE_CUSP) { - satellites.push_back(std::make_pair(counter, satellite)); + satellites.push_back(std::make_pair(counterTotal, satellite)); } ++curve_it1; counter++; + counterTotal++; } } satellitepairarrayparam_values.param_set_and_write_new_value(satellites); @@ -132,14 +134,17 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } } + std::vector LPEFilletChamfer::doEffect_path(std::vector const &path_in) { + const double gapHelper = 0.00001; std::vector pathvector_out; Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)); pwd2_in = remove_short_cuts(pwd2_in, .01); satellitepairarrayparam_values.set_pwd2(pwd2_in); std::vector > filletChamferData = satellitepairarrayparam_values.data(); + Pointwise *pointwise = new Pointwise( pwd2_in, filletChamferData); unsigned int counter = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); @@ -152,9 +157,9 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Curve &closingline = path_it->back_closed(); + const Geom::Curve &closingline = path_it->back_closed(); // the closing line segment is always of type - // LineSegment. + // Geom::LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { // closingline.isDegenerate() did not work, because it only checks for // *exact* zero length, which goes wrong for relative coordinates and @@ -164,18 +169,46 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } } unsigned int counterCurves = 0; + unsigned int first = counter; + double time0 = 0; while (curve_it1 != curve_endit) { + std::vector satVector; + Satellite sat(FILLET, true, true, false, false, 0.0, 0.0); Curve *curve_it2Fixed = (*path_it->begin()).duplicate(); - int indexFix = 0; if(!path_it->closed() || curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); - indexFix = counter; + satVector = pointwise->findSatellites(counter+1,1); + if(satVector.size()>0){ + sat = satVector[0]; + } + } else { + satVector = pointwise->findSatellites(first,1); + if(satVector.size()>0){ + sat = satVector[0]; + } + } + if(first == counter){ + satVector = pointwise->findSatellites(first,1); + if(satVector.size()>0){ + time0 = satVector[0].getTime(); + } } bool last = curve_it2 == curve_endit; + double time1 = sat.getOpositeTime((*curve_it1).toSBasis()); + double time2 = sat.getTime(); + if(time1 <= time0){ + time1 = time0 + gapHelper; + } + if(time0 == 1){ + time0 = time0 - gapHelper; + } + if(time2 == 1){ + time2 = time2 - gapHelper; + } std::vector times; - times.push_back(filletChamferData[counter].second.getTime()); - times.push_back(filletChamferData[indexFix].second.getOpositeTime((*curve_it1).toSBasis())); - times.push_back(filletChamferData[indexFix].second.getTime()); + times.push_back(time0); + times.push_back(time1); + times.push_back(time2); Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); if (counterCurves > 0) { knotCurve1->setInitial(path_out.finalPoint()); @@ -187,14 +220,17 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) Point endArcPoint = curve_it2Fixed->pointAt(times[2]); double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; double k2 = distance(endArcPoint, curve_it1->finalPoint()) * K; - CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); + Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); Ray ray1(startArcPoint, curve_it1->finalPoint()); if (cubic1) { ray1.setPoints((*cubic1)[2], startArcPoint); } Point handle1 = Point::polar(ray1.angle(),k1) + startArcPoint; - CubicBezier const *cubic2 = - dynamic_cast(&*knotCurve2); + if(time0 == 1){ + handle1 = startArcPoint; + } + Geom::CubicBezier const *cubic2 = + dynamic_cast(&*knotCurve2); Ray ray2(curve_it1->finalPoint(), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); @@ -207,76 +243,76 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) handleAngle = ray1.angle() + angle; } Point inverseHandle1 = Point::polar(handleAngle,k1) + startArcPoint; + if(time0 == 1){ + inverseHandle1 = startArcPoint; + } handleAngle = ray2.angle() + angle; if (ccwToggle) { handleAngle = ray2.angle() - angle; } Point inverseHandle2 = endArcPoint - Point::polar(handleAngle,k2); - //straigth lines arc based - Line const x_line(Point(0,0),Point(1,0)); + Line const x_line(Geom::Point(0,0),Geom::Point(1,0)); Line const angled_line(startArcPoint,endArcPoint); - double angleArc = angle_between( x_line,angled_line); - double radius = distance(startArcPoint,middle_point(startArcPoint,endArcPoint))/sin(angle/2.0); + double angleArc = Geom::angle_between( x_line,angled_line); + double radius = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint))/sin(angle/2.0); Coord rx = radius; Coord ry = rx; - if (times[1] != 1) { - if (times[1] != times[0]) { + if (times[1] != 1 || (times[1] == 1 && times[0] == times[1] - gapHelper )) { + if (times[1] != times[0] + gapHelper) { path_out.append(*knotCurve1); } - SatelliteType satType = FILLET; - if(path_it->closed() && last){ - satType = filletChamferData[counter - counterCurves].second.getSatelliteType(); - } else if (!path_it->closed() && last){ - //0 - } else { - satType = filletChamferData[counter + 1].second.getSatelliteType(); - } + SatelliteType type = FILLET; + type = sat.getSatelliteType(); if(are_near(middle_point(startArcPoint,endArcPoint),curve_it1->finalPoint(), 0.0001)){ - path_out.appendNew(endArcPoint); - } else if (satType == CHAMFER) { - unsigned int chamferSubs = 0; + //path_out.appendNew(endArcPoint); + } else if (type == CHAMFER) { + /* + unsigned int chamferSubs = type-3000; Geom::Path path_chamfer; path_chamfer.start(path_out.finalPoint()); if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); } else { - path_chamfer.appendNew(handle1, handle2, endArcPoint); + path_chamfer.appendNew(handle1, handle2, endArcPoint); } double chamfer_stepsTime = 1.0/chamferSubs; for(unsigned int i = 1; i < chamferSubs; i++){ - Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); - path_out.appendNew(chamferStep); + Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); + path_out.appendNew(chamferStep); } - path_out.appendNew(endArcPoint); - } else if (satType == INVERSE_CHAMFER) { - unsigned int chamferSubs = 2; + path_out.appendNew(endArcPoint); + /*/ + } else if (type == INVERSE_CHAMFER) { + /* + unsigned int chamferSubs = type-4000; Geom::Path path_chamfer; path_chamfer.start(path_out.finalPoint()); if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ ccwToggle = ccwToggle?0:1; path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); }else{ - path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } double chamfer_stepsTime = 1.0/chamferSubs; for(unsigned int i = 1; i < chamferSubs; i++){ - Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); - path_out.appendNew(chamferStep); + Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); + path_out.appendNew(chamferStep); } - path_out.appendNew(endArcPoint); - } else if (satType == INVERSE_FILLET) { + path_out.appendNew(endArcPoint); + */ + } else if (type == INVERSE_FILLET) { if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ ccwToggle = ccwToggle?0:1; path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); }else{ - path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } - } else if (satType == FILLET){ + } else if (type == FILLET){ if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); } else { - path_out.appendNew(handle1, handle2, endArcPoint); + path_out.appendNew(handle1, handle2, endArcPoint); } } } else { @@ -291,6 +327,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } counter++; counterCurves++; + time0 = times[2]; } pathvector_out.push_back(path_out); } @@ -299,7 +336,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) -{ +{ if (!path_in.empty()) { //satellitepairarrayparam_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); } diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index 33c6b0673..c9f40f7d1 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -24,8 +24,6 @@ ink_common_sources += \ live_effects/parameter/originalpatharray.h \ live_effects/parameter/powerstrokepointarray.cpp \ live_effects/parameter/powerstrokepointarray.h \ - live_effects/parameter/filletchamferpointarray.cpp \ - live_effects/parameter/filletchamferpointarray.h \ live_effects/parameter/satellitepairarray.cpp \ live_effects/parameter/satellitepairarray.h \ live_effects/parameter/text.cpp \ diff --git a/src/live_effects/parameter/filletchamferpointarray.cpp b/src/live_effects/parameter/filletchamferpointarray.cpp deleted file mode 100644 index 2ebe11b4b..000000000 --- a/src/live_effects/parameter/filletchamferpointarray.cpp +++ /dev/null @@ -1,881 +0,0 @@ -/* - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include <2geom/piecewise.h> -#include <2geom/sbasis-to-bezier.h> -#include <2geom/sbasis-geometric.h> -#include <2geom/svg-elliptical-arc.h> -#include <2geom/line.h> -#include <2geom/path-intersection.h> - -#include "ui/dialog/lpe-fillet-chamfer-properties.h" -#include "live_effects/parameter/filletchamferpointarray.h" -#include "live_effects/effect.h" -#include "svg/svg.h" -#include "svg/stringstream.h" -#include "knotholder.h" -#include "sp-lpe-item.h" -#include "selection.h" - -// needed for on-canvas editting: -#include "desktop.h" -#include "live_effects/lpeobject.h" -#include "helper/geom-nodetype.h" -#include "helper/geom-curves.h" -#include "ui/tools/node-tool.h" - -// TODO due to internal breakage in glibmm headers, -// this has to be included last. -#include - - -using namespace Geom; - -namespace Inkscape { - -namespace LivePathEffect { - -FilletChamferPointArrayParam::FilletChamferPointArrayParam( - const Glib::ustring &label, const Glib::ustring &tip, - const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, - Effect *effect) - : ArrayParam(label, tip, key, wr, effect, 0) -{ - knot_shape = SP_KNOT_SHAPE_DIAMOND; - knot_mode = SP_KNOT_MODE_XOR; - knot_color = 0x00ff0000; -} - -FilletChamferPointArrayParam::~FilletChamferPointArrayParam() {} - -Gtk::Widget *FilletChamferPointArrayParam::param_newWidget() -{ - return NULL; - /* - Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = - Gtk::manage( - new Inkscape::UI::Widget::RegisteredTransformedPoint( - param_label, - param_tooltip, - param_key, - *param_wr, - param_effect->getRepr(), - param_effect->getSPDoc() - ) ); - // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP) - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Affine transf = desktop->doc2dt(); - pointwdg->setTransform(transf); - pointwdg->setValue( *this ); - pointwdg->clearProgrammatically(); - pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, - _("Change point parameter")); - - Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() ); - static_cast(hbox)->pack_start(*pointwdg, true, true); - static_cast(hbox)->show_all_children(); - - return dynamic_cast (hbox); - */ -} - -void -FilletChamferPointArrayParam::param_transform_multiply(Affine const &postmul, - bool /*set*/) -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - if (prefs->getBool("/options/transform/rectcorners", true) && - _vector[1][X] <= 0) { - std::vector result; - for (std::vector::const_iterator point_it = _vector.begin(); - point_it != _vector.end(); ++point_it) { - Coord A = - (*point_it)[X] * ((postmul.expansionX() + postmul.expansionY()) / 2); - result.push_back(Point(A, (*point_it)[Y])); - } - param_set_and_write_new_value(result); - } - - // param_set_and_write_new_value( (*this) * postmul ); -} - -/** call this method to recalculate the controlpoints such that they stay at the - * same location relative to the new path. Useful after adding/deleting nodes to - * the path.*/ -void FilletChamferPointArrayParam::recalculate_controlpoints_for_new_pwd2( - Piecewise > const &pwd2_in) -{ - if (!last_pwd2.empty()) { - PathVector const pathv = - path_from_piecewise(remove_short_cuts(pwd2_in, 0.1), 0.001); - PathVector last_pathv = - path_from_piecewise(remove_short_cuts(last_pwd2, 0.1), 0.001); - std::vector result; - unsigned long counter = 0; - unsigned long counterPaths = 0; - unsigned long counterCurves = 0; - long offset = 0; - long offsetPaths = 0; - Geom::NodeType nodetype; - for (PathVector::const_iterator path_it = pathv.begin(); - path_it != pathv.end(); ++path_it) { - if (path_it->empty()) { - counterPaths++; - counter++; - continue; - } - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed() && path_it->back_closed().isDegenerate()) { - const Curve &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - counterCurves = 0; - while (curve_it1 != curve_endit) { - //if start a path get node type - if (counterCurves == 0) { - if (path_it->closed()) { - if (path_it->back_closed().isDegenerate()) { - nodetype = get_nodetype(path_it->back_open(), *curve_it1); - } else { - nodetype = get_nodetype(path_it->back_closed(), *curve_it1); - } - } else { - nodetype = NODE_NONE; - } - } else { - //check node type also whith straight lines because get_nodetype - //return non cusp node in a node inserted inside a straight line - //todo: if the path remove some nodes whith the result of a straight - //line but with handles, the node inserted into dont fire the knot - // because is not handle as cusp node by get_nodetype function - bool this_is_line = true; - bool next_is_line = is_straight_curve(*curve_it1); - this_is_line = is_straight_curve((*path_it)[counterCurves - 1]); - nodetype = get_nodetype((*path_it)[counterCurves - 1], *curve_it1); - if (this_is_line || next_is_line) { - nodetype = NODE_CUSP; - } - } - if (last_pathv.size() > pathv.size() || - (last_pathv.size() > counterPaths && - last_pathv[counterPaths].size() > counter - offset && - !are_near(curve_it1->initialPoint(), - last_pathv[counterPaths][counter - offset].initialPoint(), - 0.1))) { - if ( curve_it2 == curve_endit) { - if (last_pathv[counterPaths].size() != pathv[counterPaths].size()) { - offset = (last_pathv[counterPaths].size() - pathv[counterPaths].size()) * -1; - } else { - offset = 0; - } - offsetPaths += offset; - offset = offsetPaths; - } else if (counterCurves == 0 && last_pathv.size() <= pathv.size() && - counter - offset <= last_pathv[counterPaths].size() && - are_near(curve_it1->initialPoint(), - last_pathv[counterPaths].finalPoint(), 0.1) && - !last_pathv[counterPaths].closed()) { - long e = counter - offset + 1; - std::vector tmp = _vector; - for (unsigned long i = - last_pathv[counterPaths].size() + counter - offset; - i > counterCurves - offset + 1; i--) { - - if (tmp[i - 1][X] > 0) { - double fractpart, intpart; - fractpart = modf(tmp[i - 1][X], &intpart); - _vector[e] = Point(e + fractpart, tmp[i - 1][Y]); - } else { - _vector[e] = Point(tmp[i - 1][X], tmp[i - 1][Y]); - } - e++; - } - //delete temp vector - std::vector().swap(tmp); - if (last_pathv.size() > counterPaths) { - last_pathv[counterPaths] = last_pathv[counterPaths].reverse(); - } - } else { - if (last_pathv.size() > counterPaths) { - if (last_pathv[counterPaths].size() < - pathv[counterPaths].size()) { - offset++; - } else if (last_pathv[counterPaths].size() > - pathv[counterPaths].size()) { - offset--; - continue; - } - } else { - offset++; - } - } - double xPos = 0; - if (_vector[1][X] > 0) { - xPos = nearest_point(curve_it1->initialPoint(), pwd2_in); - } - if (nodetype == NODE_CUSP) { - result.push_back(Point(xPos, 1)); - } else { - result.push_back(Point(xPos, 0)); - } - } else { - double xPos = _vector[counter - offset][X]; - if (_vector.size() <= (unsigned)(counter - offset)) { - if (_vector[1][X] > 0) { - xPos = nearest_point(curve_it1->initialPoint(), pwd2_in); - } else { - xPos = 0; - } - } - if (nodetype == NODE_CUSP) { - double vectorY = _vector[counter - offset][Y]; - if (_vector.size() <= (unsigned)(counter - offset) || vectorY == 0) { - vectorY = 1; - } - result.push_back(Point(xPos, vectorY)); - } else { - if (_vector[1][X] < 0) { - xPos = 0; - } - result.push_back(Point(floor(xPos), 0)); - } - } - ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } - counter++; - counterCurves++; - } - counterPaths++; - } - _vector = result; - write_to_SVG(); - } -} - -void FilletChamferPointArrayParam::recalculate_knots( - Piecewise > const &pwd2_in) -{ - bool change = false; - PathVector pathv = path_from_piecewise(pwd2_in, 0.001); - if (!pathv.empty()) { - std::vector result; - int counter = 0; - int counterCurves = 0; - Geom::NodeType nodetype; - for (PathVector::const_iterator path_it = pathv.begin(); - path_it != pathv.end(); ++path_it) { - if (path_it->empty()) { - counter++; - continue; - } - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed() && path_it->back_closed().isDegenerate()) { - const Curve &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - counterCurves = 0; - while (curve_it1 != curve_endit) { - //if start a path get node type - if (counterCurves == 0) { - if (path_it->closed()) { - if (path_it->back_closed().isDegenerate()) { - nodetype = get_nodetype(path_it->back_open(), *curve_it1); - } else { - nodetype = get_nodetype(path_it->back_closed(), *curve_it1); - } - } else { - nodetype = NODE_NONE; - } - } else { - bool this_is_line = true; - bool next_is_line = is_straight_curve(*curve_it1); - this_is_line = is_straight_curve((*path_it)[counterCurves - 1]); - nodetype = get_nodetype((*path_it)[counterCurves - 1], *curve_it1); - if (this_is_line || next_is_line) { - nodetype = NODE_CUSP; - } - } - if (nodetype == NODE_CUSP) { - double vectorY = _vector[counter][Y]; - if (vectorY == 0) { - vectorY = 1; - change = true; - } - result.push_back(Point(_vector[counter][X], vectorY)); - } else { - double xPos = floor(_vector[counter][X]); - if (_vector[1][X] < 0) { - xPos = 0; - } - double vectorY = _vector[counter][Y]; - if (vectorY != 0) { - change = true; - } - result.push_back(Point(xPos, 0)); - } - ++curve_it1; - counter++; - if (curve_it2 != curve_endit) { - ++curve_it2; - } - counterCurves++; - } - } - if (change) { - _vector = result; - write_to_SVG(); - } - } -} - -void FilletChamferPointArrayParam::set_pwd2( - Piecewise > const &pwd2_in, - Piecewise > const &pwd2_normal_in) -{ - last_pwd2 = pwd2_in; - last_pwd2_normal = pwd2_normal_in; -} - -void FilletChamferPointArrayParam::set_document_unit(Glib::ustring const * value_document_unit) -{ - documentUnit = value_document_unit; -} - -void FilletChamferPointArrayParam::set_helper_size(int hs) -{ - helper_size = hs; -} - -void FilletChamferPointArrayParam::set_chamfer_steps(int value_chamfer_steps) -{ - chamfer_steps = value_chamfer_steps; -} - -void FilletChamferPointArrayParam::set_use_distance(bool use_knot_distance ) -{ - use_distance = use_knot_distance; -} - -void FilletChamferPointArrayParam::set_unit(const gchar *abbr) -{ - unit = abbr; -} - -void FilletChamferPointArrayParam::updateCanvasIndicators() -{ - std::vector ts = data(); - hp.clear(); - unsigned int i = 0; - for (std::vector::const_iterator point_it = ts.begin(); - point_it != ts.end(); ++point_it) { - double Xvalue = to_time(i, (*point_it)[X]) -i; - if (Xvalue == 0) { - i++; - continue; - } - Geom::Point ptA = last_pwd2[i].valueAt(Xvalue); - Geom::Point derivA = unit_vector(derivative(last_pwd2[i]).valueAt(Xvalue)); - Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); - derivA = derivA * rot; - Geom::Point C = ptA - derivA * helper_size; - Geom::Point D = ptA + derivA * helper_size; - Geom::Ray ray1(C, D); - char const * svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - Geom::Affine aff = Geom::Affine(); - aff *= Geom::Scale(helper_size); - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); - pathv *= aff; - pathv += last_pwd2[i].valueAt(Xvalue); - hp.push_back(pathv[0]); - hp.push_back(pathv[1]); - i++; - } -} - -void FilletChamferPointArrayParam::addCanvasIndicators( - SPLPEItem const */*lpeitem*/, std::vector &hp_vec) -{ - hp_vec.push_back(hp); -} - -double FilletChamferPointArrayParam::rad_to_len(int index, double rad) -{ - double len = 0; - std::vector subpaths = path_from_piecewise(last_pwd2, 0.1); - std::pair positions = get_positions(index, subpaths); - D2 A = last_pwd2[last_index(index, subpaths)]; - if(positions.second != 0){ - A = last_pwd2[index-1]; - }else{ - if(!subpaths[positions.first].closed()){ - return len; - } - } - D2 B = last_pwd2[index]; - Piecewise > offset_curve0 = Piecewise >(A)+rot90(unitVector(derivative(A)))*(rad); - Piecewise > offset_curve1 = Piecewise >(B)+rot90(unitVector(derivative(B)))*(rad); - Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; - Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; - Geom::Crossings cs = Geom::crossings(p0, p1); - if(cs.size() > 0){ - Point cp =p0(cs[0].ta); - double p0pt = nearest_point(cp, B); - len = time_to_len(index,p0pt); - } else { - if(rad < 0){ - len = rad_to_len(index, rad * -1); - } - } - return len; -} - -double FilletChamferPointArrayParam::len_to_rad(int index, double len) -{ - double rad = 0; - double tmp_len = _vector[index][X]; - _vector[index] = Geom::Point(len,_vector[index][Y]); - std::vector subpaths = path_from_piecewise(last_pwd2, 0.1); - std::pair positions = get_positions(index, subpaths); - Piecewise > u; - u.push_cut(0); - u.push(last_pwd2[last_index(index, subpaths)], 1); - Geom::Curve * A = path_from_piecewise(u, 0.1)[0][0].duplicate(); - Geom::Curve * B = subpaths[positions.first][positions.second].duplicate(); - std::vector times; - if(positions.second != 0){ - A = subpaths[positions.first][positions.second-1].duplicate(); - times = get_times(index-1, subpaths, false); - }else{ - if(!subpaths[positions.first].closed()){ - return rad; - } - times = get_times(last_index(index, subpaths), subpaths, true); - } - _vector[index] = Geom::Point(tmp_len,_vector[index][Y]); - Geom::Point startArcPoint = A->toSBasis().valueAt(times[1]); - Geom::Point endArcPoint = B->toSBasis().valueAt(times[2]); - Curve *knotCurve1 = A->portion(times[0], times[1]); - Curve *knotCurve2 = B->portion(times[2], 1); - Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); - Ray ray1(startArcPoint, A->finalPoint()); - if (cubic1) { - ray1.setPoints((*cubic1)[2], startArcPoint); - } - Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); - Ray ray2(B->initialPoint(), endArcPoint); - if (cubic2) { - ray2.setPoints(endArcPoint, (*cubic2)[1]); - } - bool ccwToggle = cross(A->finalPoint() - startArcPoint, endArcPoint - startArcPoint) < 0; - double distanceArc = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint)); - double angleBetween = angle_between(ray1, ray2, ccwToggle); - rad = distanceArc/sin(angleBetween/2.0); - return rad * -1; -} - -std::vector FilletChamferPointArrayParam::get_times(int index, std::vector subpaths, bool last) -{ - const double tolerance = 0.001; - const double gapHelper = 0.00001; - std::pair positions = get_positions(index, subpaths); - Curve *curve_it1; - curve_it1 = subpaths[positions.first][positions.second].duplicate(); - Coord it1_length = (*curve_it1).length(tolerance); - double time_it1, time_it2, time_it1_B, intpart; - time_it1 = modf(to_time(index, _vector[index][X]), &intpart); - if (_vector[index][Y] == 0) { - time_it1 = 0; - } - double resultLenght = 0; - time_it1_B = 1; - if (subpaths[positions.first].closed() && last) { - time_it2 = modf(to_time(index - positions.second , _vector[index - positions.second ][X]), &intpart); - resultLenght = it1_length + to_len(index - positions.second, _vector[index - positions.second ][X]); - } else if (!subpaths[positions.first].closed() && last){ - time_it2 = 0; - resultLenght = 0; - } else { - time_it2 = modf(to_time(index + 1, _vector[index + 1][X]), &intpart); - resultLenght = it1_length + to_len( index + 1, _vector[index + 1][X]); - } - if (resultLenght > 0 && time_it2 != 0) { - time_it1_B = modf(to_time(index, -resultLenght), &intpart); - } else { - if (time_it2 == 0) { - time_it1_B = 1; - } else { - time_it1_B = gapHelper; - } - } - - if ((subpaths[positions.first].closed() && last && _vector[index - positions.second][Y] == 0) || (subpaths[positions.first].size() > positions.second + 1 && _vector[index + 1][Y] == 0)) { - time_it1_B = 1; - time_it2 = 0; - } - if (time_it1_B < time_it1) { - time_it1_B = time_it1 + gapHelper; - } - std::vector out; - out.push_back(time_it1); - out.push_back(time_it1_B); - out.push_back(time_it2); - return out; -} - -std::pair FilletChamferPointArrayParam::get_positions(int index, std::vector subpaths) -{ - int counter = -1; - std::size_t first = 0; - std::size_t second = 0; - for (PathVector::const_iterator path_it = subpaths.begin(); path_it != subpaths.end(); ++path_it) { - if (path_it->empty()) - continue; - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); - // the closing line segment is always of type - // Geom::LineSegment. - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - // closingline.isDegenerate() did not work, because it only checks for - // *exact* zero length, which goes wrong for relative coordinates and - // rounding errors... - // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); - } - } - first++; - second = 0; - while (curve_it1 != curve_endit) { - counter++; - second++; - if(counter == index){ - break; - } - ++curve_it1; - } - if(counter == index){ - break; - } - } - first--; - second--; - std::pair out(first, second); - return out; -} - -int FilletChamferPointArrayParam::last_index(int index, std::vector subpaths) -{ - int counter = -1; - bool inSubpath = false; - for (PathVector::const_iterator path_it = subpaths.begin(); path_it != subpaths.end(); ++path_it) { - if (path_it->empty()) - continue; - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); - } - } - while (curve_it1 != curve_endit) { - counter++; - if(counter == index){ - inSubpath = true; - } - ++curve_it1; - } - if(inSubpath){ - break; - } - } - if(!inSubpath){ - counter = -1; - } - return counter; -} - - -double FilletChamferPointArrayParam::len_to_time(int index, double len) -{ - double t = 0; - if (last_pwd2.size() > (unsigned) index) { - if (len != 0) { - if (last_pwd2[index][0].degreesOfFreedom() != 2) { - Piecewise > u; - u.push_cut(0); - u.push(last_pwd2[index], 1); - std::vector t_roots = roots(arcLengthSb(u) - std::abs(len)); - if (t_roots.size() > 0) { - t = t_roots[0]; - } - } else { - double lenghtPart = 0; - if (last_pwd2.size() > (unsigned) index) { - lenghtPart = length(last_pwd2[index], EPSILON); - } - if (std::abs(len) < lenghtPart && lenghtPart != 0) { - t = std::abs(len) / lenghtPart; - } - } - } - t = double(index) + t; - } else { - t = double(last_pwd2.size() - 1); - } - - return t; -} - -double FilletChamferPointArrayParam::time_to_len(int index, double time) -{ - double intpart; - double len = 0; - time = modf(time, &intpart); - double lenghtPart = 0; - if (last_pwd2.size() <= (unsigned) index || time == 0) { - return len; - } - if (last_pwd2[index][0].degreesOfFreedom() != 2) { - Piecewise > u; - u.push_cut(0); - u.push(last_pwd2[index], 1); - u = portion(u, 0, time); - return length(u, 0.001) * -1; - } - lenghtPart = length(last_pwd2[index], EPSILON); - return (time * lenghtPart) * -1; -} - -double FilletChamferPointArrayParam::to_time(int index, double A) -{ - if (A > 0) { - return A; - } else { - return len_to_time(index, A); - } -} - -double FilletChamferPointArrayParam::to_len(int index, double A) -{ - if (A > 0) { - return time_to_len(index, A); - } else { - return A; - } -} - -void FilletChamferPointArrayParam::set_oncanvas_looks(SPKnotShapeType shape, - SPKnotModeType mode, - guint32 color) -{ - knot_shape = shape; - knot_mode = mode; - knot_color = color; -} - -FilletChamferPointArrayParamKnotHolderEntity:: -FilletChamferPointArrayParamKnotHolderEntity( - FilletChamferPointArrayParam *p, unsigned int index) - : _pparam(p), _index(index) {} - -void FilletChamferPointArrayParamKnotHolderEntity::knot_set(Point const &p, - Point const &/*origin*/, - guint state) -{ - using namespace Geom; - - if (!valid_index(_index)) { - return; - } - Piecewise > const &pwd2 = _pparam->get_pwd2(); - double t = nearest_point(p, pwd2[_index]); - Geom::Point const s = snap_knot_position(pwd2[_index].valueAt(t), state); - t = nearest_point(s, pwd2[_index]); - if (t == 1) { - t = 0.9999; - } - t += _index; - - if (_pparam->_vector.at(_index)[X] <= 0) { - _pparam->_vector.at(_index) = - Point(_pparam->time_to_len(_index, t), _pparam->_vector.at(_index)[Y]); - } else { - _pparam->_vector.at(_index) = Point(t, _pparam->_vector.at(_index)[Y]); - } - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); -} - -Point FilletChamferPointArrayParamKnotHolderEntity::knot_get() const -{ - using namespace Geom; - - if (!valid_index(_index)) { - return Point(infinity(), infinity()); - } - - Piecewise > const &pwd2 = _pparam->get_pwd2(); - - double time_it = _pparam->to_time(_index, _pparam->_vector.at(_index)[X]); - Point canvas_point = pwd2.valueAt(time_it); - - _pparam->updateCanvasIndicators(); - return canvas_point; - -} - -void FilletChamferPointArrayParamKnotHolderEntity::knot_click(guint state) -{ - if (state & GDK_CONTROL_MASK) { - if (state & GDK_MOD1_MASK) { - _pparam->_vector.at(_index) = Point(_index, _pparam->_vector.at(_index)[Y]); - _pparam->param_set_and_write_new_value(_pparam->_vector); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - }else{ - using namespace Geom; - int type = (int)_pparam->_vector.at(_index)[Y]; - if (type >=3000 && type < 4000){ - type = 3; - } - if (type >=4000 && type < 5000){ - type = 4; - } - switch(type){ - case 1: - type = 2; - break; - case 2: - type = _pparam->chamfer_steps + 3000; - break; - case 3: - type = _pparam->chamfer_steps + 4000; - break; - default: - type = 1; - break; - } - _pparam->_vector.at(_index) = Point(_pparam->_vector.at(_index)[X], (double)type); - _pparam->param_set_and_write_new_value(_pparam->_vector); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - const gchar *tip; - if (type >=3000 && type < 4000){ - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type >=4000 && type < 5000) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == 2) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - this->knot->tip = g_strdup(tip); - this->knot->show(); - } - } else if (state & GDK_SHIFT_MASK) { - double xModified = _pparam->_vector.at(_index).x(); - if(xModified < 0 && !_pparam->use_distance){ - xModified = _pparam->len_to_rad(_index, _pparam->_vector.at(_index).x()); - } - std::vector subpaths = path_from_piecewise(_pparam->last_pwd2, 0.1); - std::pair positions = _pparam->get_positions(_index, subpaths); - D2 A = _pparam->last_pwd2[_pparam->last_index(_index, subpaths)]; - if(positions.second != 0){ - A = _pparam->last_pwd2[_index-1]; - } - D2 B = _pparam->last_pwd2[_index]; - bool aprox = (A[0].degreesOfFreedom() != 2 || B[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; - Geom::Point offset = Geom::Point(xModified, _pparam->_vector.at(_index).y()); - Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( - this->desktop, offset, this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit); - } - -} - -void FilletChamferPointArrayParamKnotHolderEntity::knot_set_offset( - Geom::Point offset) -{ - double xModified = offset.x(); - if(xModified < 0 && !_pparam->use_distance){ - xModified = _pparam->rad_to_len(_index, offset.x()); - } - _pparam->_vector.at(_index) = Geom::Point(xModified, offset.y()); - this->parent_holder->knot_ungrabbed_handler(this->knot, 0); -} - -void FilletChamferPointArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item) -{ - recalculate_knots(get_pwd2()); - for (unsigned int i = 0; i < _vector.size(); ++i) { - if (_vector[i][Y] <= 0) { - continue; - } - const gchar *tip; - if (_vector[i][Y] >=3000 && _vector[i][Y] < 4000){ - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (_vector[i][Y] >=4000 && _vector[i][Y] < 5000) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (_vector[i][Y] == 2) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - FilletChamferPointArrayParamKnotHolderEntity *e = - new FilletChamferPointArrayParamKnotHolderEntity(this, i); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); - knotholder->add(e); - } - updateCanvasIndicators(); -} - -} /* namespace LivePathEffect */ - -} /* namespace Inkscape */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/filletchamferpointarray.h b/src/live_effects/parameter/filletchamferpointarray.h deleted file mode 100644 index 6e5cce353..000000000 --- a/src/live_effects/parameter/filletchamferpointarray.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_FILLET_CHAMFER_POINT_ARRAY_H -#define INKSCAPE_LIVEPATHEFFECT_FILLET_CHAMFER_POINT_ARRAY_H - -/* - * Inkscape::LivePathEffectParameters - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include <2geom/point.h> - -#include "live_effects/parameter/array.h" - -#include "knot-holder-entity.h" - -namespace Inkscape { - -namespace LivePathEffect { - -class FilletChamferPointArrayParamKnotHolderEntity; - -class FilletChamferPointArrayParam : public ArrayParam { -public: - FilletChamferPointArrayParam(const Glib::ustring &label, - const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, - Effect *effect); - virtual ~FilletChamferPointArrayParam(); - - virtual Gtk::Widget *param_newWidget(); - - virtual void param_transform_multiply(Geom::Affine const &postmul, - bool /*set*/); - - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); - virtual double to_time(int index, double A); - virtual double to_len(int index, double A); - virtual double rad_to_len(int index, double rad); - virtual double len_to_rad(int index, double len); - virtual double len_to_time(int index, double len); - virtual double time_to_len(int index, double time); - virtual std::pair get_positions(int index, std::vector subpaths); - virtual int last_index(int index, std::vector subpaths); - std::vector get_times(int index, std::vector subpaths, bool last); - virtual void set_helper_size(int hs); - virtual void set_use_distance(bool use_knot_distance); - virtual void set_chamfer_steps(int value_chamfer_steps); - virtual void set_document_unit(Glib::ustring const * value_document_unit); - virtual void set_unit(const gchar *abbr); - virtual void addCanvasIndicators(SPLPEItem const *lpeitem, - std::vector &hp_vec); - virtual bool providesKnotHolderEntities() const { - return true; - } - virtual void updateCanvasIndicators(); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item); - - void set_pwd2(Geom::Piecewise > const &pwd2_in, - Geom::Piecewise > const &pwd2_normal_in); - Geom::Piecewise > const &get_pwd2() const { - return last_pwd2; - } - Geom::Piecewise > const &get_pwd2_normal() const { - return last_pwd2_normal; - } - - void recalculate_controlpoints_for_new_pwd2( - Geom::Piecewise > const &pwd2_in); - void recalculate_knots( - Geom::Piecewise > const &pwd2_in); - friend class FilletChamferPointArrayParamKnotHolderEntity; - -private: - FilletChamferPointArrayParam(const FilletChamferPointArrayParam &); - FilletChamferPointArrayParam &operator=(const FilletChamferPointArrayParam &); - - SPKnotShapeType knot_shape; - SPKnotModeType knot_mode; - guint32 knot_color; - int helper_size; - int chamfer_steps; - bool use_distance; - const gchar *unit; - Glib::ustring const * documentUnit; - Geom::PathVector hp; - - Geom::Piecewise > last_pwd2; - Geom::Piecewise > last_pwd2_normal; -}; - -class FilletChamferPointArrayParamKnotHolderEntity : public KnotHolderEntity { -public: - FilletChamferPointArrayParamKnotHolderEntity(FilletChamferPointArrayParam *p, - unsigned int index); - virtual ~FilletChamferPointArrayParamKnotHolderEntity() {} - - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, - guint state); - virtual Geom::Point knot_get() const; - virtual void knot_click(guint state); - virtual void knot_set_offset(Geom::Point offset); - - /*Checks whether the index falls within the size of the parameter's vector*/ - bool valid_index(unsigned int index) const { - return (_pparam->_vector.size() > index); - } - ; - -private: - FilletChamferPointArrayParam *_pparam; - unsigned int _index; -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index b318933a7..e69de29bb 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 3807e98c8..e69de29bb 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 -// : -- cgit v1.2.3 From eae224916a20ea75f80471af2df057e7e74b0c9e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 19 Feb 2015 21:59:45 +0100 Subject: reducing size in pointwise LPE data (bzr r13645.1.18) --- src/2geom/satellite-enum.h | 10 +++++----- src/live_effects/lpe-fillet-chamfer.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/2geom/satellite-enum.h b/src/2geom/satellite-enum.h index 474e98547..bcd8d1bb3 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 3b1b1697c..e9d9a21b1 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -262,11 +262,11 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (times[1] != times[0] + gapHelper) { path_out.append(*knotCurve1); } - SatelliteType type = FILLET; + SatelliteType type = F; type = sat.getSatelliteType(); if(are_near(middle_point(startArcPoint,endArcPoint),curve_it1->finalPoint(), 0.0001)){ //path_out.appendNew(endArcPoint); - } else if (type == CHAMFER) { + } else if (type == C) { /* unsigned int chamferSubs = type-3000; Geom::Path path_chamfer; @@ -283,7 +283,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } path_out.appendNew(endArcPoint); /*/ - } else if (type == INVERSE_CHAMFER) { + } else if (type == IC) { /* unsigned int chamferSubs = type-4000; Geom::Path path_chamfer; @@ -301,14 +301,14 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } path_out.appendNew(endArcPoint); */ - } else if (type == INVERSE_FILLET) { + } else if (type == IF) { if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ ccwToggle = ccwToggle?0:1; path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); }else{ path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } - } else if (type == FILLET){ + } else if (type == F){ if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); } else { -- cgit v1.2.3 From aa9e36cd93c4f71ff8eb0a6fc24d46933fdf7d14 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 19 Feb 2015 22:06:37 +0100 Subject: fixed some bugs (bzr r13645.1.19) --- src/2geom/satellite.h | 4 ++-- src/live_effects/lpe-fillet-chamfer.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index a83de5af2..7b524f912 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 e9d9a21b1..0ef8b5a0e 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -87,7 +87,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) --curve_end; int counter = 0; while (curve_it1 != curve_endit) { - Satellite satellite(FILLET, true, true, false, false, 0.0, 0.0); + Satellite satellite(F, true, true, false, false, 0.0, 0.0); Geom::NodeType nodetype; if (counter==0) { if (path_it->closed()) { @@ -173,7 +173,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double time0 = 0; while (curve_it1 != curve_endit) { std::vector satVector; - Satellite sat(FILLET, true, true, false, false, 0.0, 0.0); + Satellite sat(F, true, true, false, false, 0.0, 0.0); Curve *curve_it2Fixed = (*path_it->begin()).duplicate(); if(!path_it->closed() || curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); -- cgit v1.2.3 From 83e726c8fb391f0cbbccc9b286bfecefc730dbc7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 23 Feb 2015 23:16:39 +0100 Subject: Added flexible/fixed to fillet chamfer and fix bugs (bzr r13645.1.20) --- src/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(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index d7d5afc63..aa1620e8a 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 d48321832..e7646d96c 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 b8ddd040b..9a2fa0a10 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 7b524f912..105297f48 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 0ef8b5a0e..73c504deb 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -45,10 +45,13 @@ FMConverter(FilletMethodData, FM_END); LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this), - method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO) + method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), + flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), + pointwise() { registerParameter(&satellitepairarrayparam_values); registerParameter(&method); + registerParameter(&flexible); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -60,11 +63,11 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPShape * shape = dynamic_cast(splpeitem); if (shape) { PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); - std::vector > satellites; Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, .01); satellitepairarrayparam_values.set_pwd2(pwd2_in); int counterTotal = 0; + std::vector > satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; @@ -87,7 +90,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) --curve_end; int counter = 0; while (curve_it1 != curve_endit) { - Satellite satellite(F, true, true, false, false, 0.0, 0.0); + Satellite satellite(F, flexible, true, false, false, 0.0, 0.0); Geom::NodeType nodetype; if (counter==0) { if (path_it->closed()) { @@ -114,7 +117,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } - void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { SPLPEItem * splpeitem = const_cast(lpeItem); @@ -126,9 +128,23 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); + Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(original_pathv)); pwd2_in = remove_short_cuts(pwd2_in, .01); + //wating to recalculate + //recalculate_controlpoints_for_new_pwd2(pwd2_in); satellitepairarrayparam_values.set_pwd2(pwd2_in); + std::vector > satellites = satellitepairarrayparam_values.data(); + pointwise = new Pointwise( pwd2_in,satellites); + bool changed = false; + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(it->second.getIsTime() != flexible){ + it->second.setIsTime(flexible); + changed = true; + } + } + if(changed){ + satellitepairarrayparam_values.param_set_and_write_new_value(satellites); + } } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -140,18 +156,14 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) { const double gapHelper = 0.00001; std::vector pathvector_out; - Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)); - pwd2_in = remove_short_cuts(pwd2_in, .01); - satellitepairarrayparam_values.set_pwd2(pwd2_in); - std::vector > filletChamferData = satellitepairarrayparam_values.data(); - Pointwise *pointwise = new Pointwise( pwd2_in, filletChamferData); unsigned int counter = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); for (PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { - if (path_it->empty()) + if (path_it->empty()){ continue; + } Geom::Path path_out; Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); @@ -172,9 +184,13 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) unsigned int first = counter; double time0 = 0; while (curve_it1 != curve_endit) { + if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ + g_warning("LPE Fillet not handle degenerate curves."); + return path_in; + } std::vector satVector; - Satellite sat(F, true, true, false, false, 0.0, 0.0); - Curve *curve_it2Fixed = (*path_it->begin()).duplicate(); + Satellite sat; + Curve *curve_it2Fixed = path_it->begin()->duplicate(); if(!path_it->closed() || curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); satVector = pointwise->findSatellites(counter+1,1); @@ -193,33 +209,38 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) time0 = satVector[0].getTime(); } } + bool last = curve_it2 == curve_endit; double time1 = sat.getOpositeTime((*curve_it1).toSBasis()); double time2 = sat.getTime(); if(time1 <= time0){ - time1 = time0 + gapHelper; - } - if(time0 == 1){ - time0 = time0 - gapHelper; - } - if(time2 == 1){ - time2 = time2 - gapHelper; + time1 = time0; } std::vector times; times.push_back(time0); times.push_back(time1); times.push_back(time2); + std::cout << ":::" << counter << ":::::::::::::::\n"; + std::cout << time0 << "::Time 0\n"; + std::cout << time1 << "::Time 1\n"; + std::cout << time2 << "::Time 2\n"; Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); if (counterCurves > 0) { knotCurve1->setInitial(path_out.finalPoint()); } else { path_out.start((*curve_it1).pointAt(times[0])); } - Curve *knotCurve2 = curve_it2Fixed->portion(times[2], 1); + Point startArcPoint = knotCurve1->finalPoint(); Point endArcPoint = curve_it2Fixed->pointAt(times[2]); + if(times[2] == 1){ + endArcPoint = curve_it2Fixed->pointAt(times[2]-gapHelper); + } + if(times[1] == times[0]){ + startArcPoint = knotCurve1->pointAt(1-gapHelper); + } double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; - double k2 = distance(endArcPoint, curve_it1->finalPoint()) * K; + double k2 = distance(endArcPoint, curve_it2Fixed->initialPoint()) * K; Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); Ray ray1(startArcPoint, curve_it1->finalPoint()); if (cubic1) { @@ -229,13 +250,14 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if(time0 == 1){ handle1 = startArcPoint; } - Geom::CubicBezier const *cubic2 = - dynamic_cast(&*knotCurve2); - Ray ray2(curve_it1->finalPoint(), endArcPoint); + Curve *knotCurve2 = curve_it2Fixed->portion(times[2], 1); + Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); + Ray ray2(curve_it2Fixed->initialPoint(), endArcPoint); if (cubic2) { ray2.setPoints(endArcPoint, (*cubic2)[1]); } Point handle2 = endArcPoint - Point::polar(ray2.angle(),k2); + bool ccwToggle = cross(curve_it1->finalPoint() - startArcPoint, endArcPoint - startArcPoint) < 0; double angle = angle_between(ray1, ray2, ccwToggle); double handleAngle = ray1.angle() - angle; @@ -251,21 +273,28 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) handleAngle = ray2.angle() - angle; } Point inverseHandle2 = endArcPoint - Point::polar(handleAngle,k2); + if(times[2] == 1){ + endArcPoint = curve_it2Fixed->pointAt(times[2]); + } + if(times[1] == times[0]){ + startArcPoint = knotCurve1->pointAt(1); + } Line const x_line(Geom::Point(0,0),Geom::Point(1,0)); Line const angled_line(startArcPoint,endArcPoint); double angleArc = Geom::angle_between( x_line,angled_line); double radius = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint))/sin(angle/2.0); Coord rx = radius; Coord ry = rx; - - if (times[1] != 1 || (times[1] == 1 && times[0] == times[1] - gapHelper )) { - if (times[1] != times[0] + gapHelper) { - path_out.append(*knotCurve1); + if (times[1] != 1) { + if (times[1] != times[0] || times[1] == times[0] == 1) { + if(!knotCurve1->isDegenerate()){ + path_out.append(*knotCurve1); + } } SatelliteType type = F; type = sat.getSatelliteType(); if(are_near(middle_point(startArcPoint,endArcPoint),curve_it1->finalPoint(), 0.0001)){ - //path_out.appendNew(endArcPoint); + // path_out.appendNew(endArcPoint); } else if (type == C) { /* unsigned int chamferSubs = type-3000; @@ -316,11 +345,20 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } } } else { - path_out.append(*knotCurve1); + if(!knotCurve1->isDegenerate()){ + path_out.append(*knotCurve1); + } } if (path_it->closed() && last) { path_out.close(); } + /* + if(!path_it->closed() || curve_it2 != curve_endit){ + satellites[counter + 1] = std::make_pair(counter + 1, sat); + } else { + satellites[first] = std::make_pair(first, sat); + } + */ ++curve_it1; if (curve_it2 != curve_endit) { ++curve_it2; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 2c0dfcaab..f5c4f14ea 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -42,6 +42,9 @@ public: private: EnumParam method; + BoolParam flexible; + Geom::Pointwise *pointwise; + LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 8145d62a3..e9775da24 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -115,15 +115,15 @@ protected: void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { str << nVector.first; str << ","; - str << nVector.second.getSatelliteTypeGchar(); + str << nVector.second.getSatelliteTypeGchar(); str << "*"; - str << nVector.second.getIsTime(); + str << g_strdup(nVector.second.getIsTime() ? "true" : "false"); str << "*"; - str << nVector.second.getActive(); + str << g_strdup(nVector.second.getActive() ? "true" : "false"); str << "*"; - str << nVector.second.getHasMirror(); + str << g_strdup(nVector.second.getHasMirror() ? "true" : "false"); str << "*"; - str << nVector.second.getHidden(); + str << g_strdup(nVector.second.getHidden() ? "true" : "false"); str << "*"; str << nVector.second.getSize(); str << "*"; -- cgit v1.2.3 From 7086c79862b2d9bcd9f12f078854ad7e117d2cde Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 27 Feb 2015 22:52:58 +0100 Subject: fixing write knot (bzr r13645.1.22) --- src/live_effects/lpe-fillet-chamfer.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 73c504deb..2354aa5ed 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -120,6 +120,15 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { SPLPEItem * splpeitem = const_cast(lpeItem); + if (splpeitem) { + // This writes all parameters to SVG. Is this sufficiently efficient or should we only + // write the ones that were changed? + Inkscape::LivePathEffect::Effect *lpe = splpeitem->getCurrentLPE(); + if (lpe) { + LivePathEffectObject *lpeobj = lpe->getLPEObj(); + lpeobj->updateRepr(); + } + } SPShape * shape = dynamic_cast(splpeitem); if (shape) { SPCurve *c = shape->getCurve(); -- cgit v1.2.3 From 43c5af94d24cd408f7b369545e96cf9192f6ba90 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 28 Feb 2015 13:13:49 +0100 Subject: improving code (bzr r13645.1.24) --- src/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(-) (limited to 'src') diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp index 9a2fa0a10..5b362d87f 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 105297f48..dd8e4d9d0 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 2354aa5ed..39acdca80 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,6 +16,7 @@ #include "live_effects/lpe-fillet-chamfer.h" +#include "live_effects/lpeobject.h" #include #include #include <2geom/pointwise.h> @@ -120,15 +121,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { SPLPEItem * splpeitem = const_cast(lpeItem); - if (splpeitem) { - // This writes all parameters to SVG. Is this sufficiently efficient or should we only - // write the ones that were changed? - Inkscape::LivePathEffect::Effect *lpe = splpeitem->getCurrentLPE(); - if (lpe) { - LivePathEffectObject *lpeobj = lpe->getLPEObj(); - lpeobj->updateRepr(); - } - } SPShape * shape = dynamic_cast(splpeitem); if (shape) { SPCurve *c = shape->getCurve(); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 473b561d2..6dad9fcc8 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -56,10 +56,10 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ gchar ** strarray = g_strsplit(str, "*", 0); if(strarray[6] && !strarray[7]){ sat->setSatelliteType(strarray[0]); - sat->setIsTime(helperfns_read_bool(strarray[1], true)); - sat->setActive(helperfns_read_bool(strarray[2], true)); - sat->setHasMirror(helperfns_read_bool(strarray[3], false)); - sat->setHidden(helperfns_read_bool(strarray[4], false)); + sat->setIsTime(strncmp(strarray[1],"1",1) == 0); + sat->setActive(strncmp(strarray[2],"1",1) == 0); + sat->setHasMirror(strncmp(strarray[3],"1",1) == 0); + sat->setHidden(strncmp(strarray[4],"1",1) == 0); double time,size; sp_svg_number_read_d(strarray[5], &size); sp_svg_number_read_d(strarray[6], &time); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index e9775da24..ff406d792 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -117,13 +117,13 @@ protected: str << ","; str << nVector.second.getSatelliteTypeGchar(); str << "*"; - str << g_strdup(nVector.second.getIsTime() ? "true" : "false"); + str << nVector.second.getIsTime(); str << "*"; - str << g_strdup(nVector.second.getActive() ? "true" : "false"); + str << nVector.second.getActive(); str << "*"; - str << g_strdup(nVector.second.getHasMirror() ? "true" : "false"); + str << nVector.second.getHasMirror(); str << "*"; - str << g_strdup(nVector.second.getHidden() ? "true" : "false"); + str << nVector.second.getHidden(); str << "*"; str << nVector.second.getSize(); str << "*"; -- cgit v1.2.3 From 00d08a0f4bca11e775bbacf3d512676a0493c1a3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 1 Mar 2015 01:18:02 +0100 Subject: adding mirror knot (bzr r13645.1.25) --- src/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 +- src/live_effects/parameter/satellitepairarray.cpp | 62 ++++++++++++++++++++--- src/live_effects/parameter/satellitepairarray.h | 11 ++-- 9 files changed, 195 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index aa1620e8a..bc468343c 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 e7646d96c..5937264ad 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 5b362d87f..21361147c 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 dd8e4d9d0..c66770bb6 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 39acdca80..41c6a7090 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -65,8 +65,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) if (shape) { PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); - pwd2_in = remove_short_cuts(pwd2_in, .01); - satellitepairarrayparam_values.set_pwd2(pwd2_in); + pwd2_in = remove_short_cuts(pwd2_in, 0.01); int counterTotal = 0; std::vector > satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { @@ -110,6 +109,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) counterTotal++; } } + pointwise = new Pointwise( pwd2_in,satellites); satellitepairarrayparam_values.param_set_and_write_new_value(satellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -130,20 +130,31 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(original_pathv)); - pwd2_in = remove_short_cuts(pwd2_in, .01); + pwd2_in = remove_short_cuts(pwd2_in, 0.01); //wating to recalculate //recalculate_controlpoints_for_new_pwd2(pwd2_in); - satellitepairarrayparam_values.set_pwd2(pwd2_in); std::vector > satellites = satellitepairarrayparam_values.data(); - pointwise = new Pointwise( pwd2_in,satellites); + pointwise->setPwd2(pwd2_in); + pointwise->setSatellites(satellites); + satellitepairarrayparam_values.set_pointwise(pointwise); bool changed = false; for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(it->second.getIsTime() != flexible){ it->second.setIsTime(flexible); + double ammount = it->second.getAmmount(); + D2 d2_in = pwd2_in[it->first]; + if(it->second.getIsTime()){ + double time = it->second.toTime(ammount,d2_in); + it->second.setAmmount(time); + } else { + double size = it->second.toSize(ammount,d2_in); + it->second.setAmmount(size); + } changed = true; } } if(changed){ + pointwise->setSatellites(satellites); satellitepairarrayparam_values.param_set_and_write_new_value(satellites); } } else { @@ -207,13 +218,13 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if(first == counter){ satVector = pointwise->findSatellites(first,1); if(satVector.size()>0){ - time0 = satVector[0].getTime(); + time0 = satVector[0].getTime(curve_it2Fixed->toSBasis()); } } bool last = curve_it2 == curve_endit; double time1 = sat.getOpositeTime((*curve_it1).toSBasis()); - double time2 = sat.getTime(); + double time2 = sat.getTime(curve_it2Fixed->toSBasis()); if(time1 <= time0){ time1 = time0; } diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 6dad9fcc8..2c3d823a5 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -60,11 +60,11 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ sat->setActive(strncmp(strarray[2],"1",1) == 0); sat->setHasMirror(strncmp(strarray[3],"1",1) == 0); sat->setHidden(strncmp(strarray[4],"1",1) == 0); - double time,size; - sp_svg_number_read_d(strarray[5], &size); - sp_svg_number_read_d(strarray[6], &time); - sat->setSize(size); - sat->setTime(time); + double ammount,angle; + sp_svg_number_read_d(strarray[5], &ammount); + sp_svg_number_read_d(strarray[6], &angle); + sat->setAmmount(ammount); + sat->setAngle(angle); g_strfreev (strarray); return 1; } diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index ff406d792..1a5823199 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -125,9 +125,9 @@ protected: str << "*"; str << nVector.second.getHidden(); str << "*"; - str << nVector.second.getSize(); + str << nVector.second.getAmmount(); str << "*"; - str < > const &pwd2_in) +void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) { - last_pwd2 = pwd2_in; + last_pointwise = pointwise; } void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, @@ -55,6 +54,7 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { for (unsigned int i = 0; i < _vector.size(); ++i) { + addKnotHolderEntitieMirrored(knotholder, desktop, item, i); const gchar *tip; tip = _("Fillet: Ctrl+Click toggle type, " "Shift+Click open dialog, " @@ -67,6 +67,19 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, } } +void SatellitePairArrayParam::addKnotHolderEntitieMirrored(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item, int i) +{ + const gchar *tip; + tip = _("Mirror ppp"); + SatellitePairArrayParamKnotHolderEntity *e = + new SatellitePairArrayParamKnotHolderEntity(this, i + _vector.size()); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + knot_shape, knot_mode, knot_color); + knotholder->add(e); +} + SatellitePairArrayParamKnotHolderEntity::SatellitePairArrayParamKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index) : _pparam(p), @@ -80,8 +93,28 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, Point const &/*origin*/, guint state) { - Geom::Point const s = snap_knot_position(p, state); - _pparam->_vector.at(_index).second.setPosition(s,_pparam->last_pwd2[_pparam->_vector.at(_index).first]); + Geom::Point s = snap_knot_position(p, state); + int index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + std::pair satellite = _pparam->_vector.at(index); + Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + if(_pparam->_vector.size() <= _index){ + boost::optional > d2_in = pointwise->getCurveIn(satellite); + if(d2_in){ + double mirrorTime = Geom::nearest_point(s, *d2_in); + double size = satellite.second.toSize(mirrorTime, *d2_in); + double lenght = Geom::length(*d2_in, Geom::EPSILON) - size; + double time = satellite.second.toTime(lenght,pwd2[satellite.first]); + s = pwd2[satellite.first].valueAt(time); + satellite.second.setPosition(s,pwd2[satellite.first]); + } + } else { + satellite.second.setPosition(s,pwd2[satellite.first]); + } + _pparam->_vector.at(index) = satellite; SPLPEItem * splpeitem = dynamic_cast(item); if(splpeitem){ sp_lpe_item_update_patheffect(splpeitem, false, false); @@ -91,7 +124,24 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, Geom::Point SatellitePairArrayParamKnotHolderEntity::knot_get() const { - Geom::Point const canvas_point = _pparam->_vector.at(_index).second.getPosition(_pparam->last_pwd2[_pparam->_vector.at(_index).first]); + Geom::Point tmpPoint; + int index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + std::pair satellite = _pparam->_vector.at(index); + Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + if( _index >= _pparam->_vector.size()){ + tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); + boost::optional > d2_in = pointwise->getCurveIn(satellite); + if(d2_in){ + tmpPoint = (*d2_in).valueAt(satellite.second.getOpositeTime(*d2_in)); + } + } else { + tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); + } + Geom::Point const canvas_point = tmpPoint; return canvas_point; } diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index ff1924829..dde844fd1 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -21,6 +21,7 @@ #include #include "live_effects/parameter/array.h" #include "knot-holder-entity.h" +#include <2geom/pointwise.h> namespace Inkscape { @@ -47,10 +48,8 @@ public: return true; } virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - void set_pwd2(Geom::Piecewise > const &pwd2_in); - Geom::Piecewise > const &get_pwd2() const { - return last_pwd2; - } + virtual void addKnotHolderEntitieMirrored(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, int i); + void set_pointwise(Geom::Pointwise *pointwise); friend class SatellitePairArrayParamKnotHolderEntity; private: @@ -60,8 +59,8 @@ private: SPKnotShapeType knot_shape; SPKnotModeType knot_mode; guint32 knot_color; - - Geom::Piecewise > last_pwd2; + + Geom::Pointwise *last_pointwise; }; -- cgit v1.2.3 From f77b5496f69a5391bc548be95c85659539a92fe9 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 1 Mar 2015 23:23:56 +0100 Subject: added mirror knots (bzr r13645.1.26) --- src/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 ++ src/live_effects/parameter/satellitepairarray.cpp | 35 ++++++++++++++++- 9 files changed, 145 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index bc468343c..3c359eddc 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 5937264ad..c7426dc9d 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 21361147c..9c253523e 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 c66770bb6..7581e6e34 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 41c6a7090..d46d0f4ff 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -48,11 +48,13 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this), method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), + mirrorKnots(_("Mirror Knots"), _("Mirror Knots"), "mirrorKnots", &wr, this, true), pointwise() { registerParameter(&satellitepairarrayparam_values); registerParameter(&method); registerParameter(&flexible); + registerParameter(&mirrorKnots); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -90,24 +92,36 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) --curve_end; int counter = 0; while (curve_it1 != curve_endit) { - Satellite satellite(F, flexible, true, false, false, 0.0, 0.0); - Geom::NodeType nodetype; + bool isStart = false; + if(counter == 0){ + isStart = true; + } + bool isClosing = false; + if(path_it->closed() && curve_it1 == curve_end){ + isClosing = true; + } + bool active = true; + bool hidden = false; if (counter==0) { if (path_it->closed()) { - nodetype = get_nodetype(*curve_end, *curve_it1); } else { - nodetype = NODE_NONE; + active = false; } - } else { - nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); - } - if (nodetype == NODE_CUSP) { - satellites.push_back(std::make_pair(counterTotal, satellite)); } + Satellite satellite(F, flexible, isClosing, isStart, active, mirrorKnots, hidden, 0.0, 0.0); + satellites.push_back(std::make_pair(counterTotal, satellite)); ++curve_it1; counter++; counterTotal++; } + if (!path_it->closed()){ + bool active = false; + bool isClosing = false; + bool isStart = false; + bool hidden = false; + Satellite satellite(F, flexible, isClosing, isStart, active, mirrorKnots, hidden, 0.0, 0.0); + satellites.push_back(std::make_pair(counterTotal, satellite)); + } } pointwise = new Pointwise( pwd2_in,satellites); satellitepairarrayparam_values.param_set_and_write_new_value(satellites); @@ -152,6 +166,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } changed = true; } + if(it->second.getHasMirror() != mirrorKnots){ + it->second.setHasMirror(mirrorKnots); + changed = true; + } } if(changed){ pointwise->setSatellites(satellites); @@ -218,12 +236,16 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if(first == counter){ satVector = pointwise->findSatellites(first,1); if(satVector.size()>0){ - time0 = satVector[0].getTime(curve_it2Fixed->toSBasis()); + time0 = satVector[0].getTime(path_it->begin()->duplicate()->toSBasis()); } } bool last = curve_it2 == curve_endit; - double time1 = sat.getOpositeTime((*curve_it1).toSBasis()); + double s = sat.getAmmount(); + if(sat.getIsTime()){ + s = sat.toSize(s, curve_it2Fixed->toSBasis()); + } + double time1 = sat.getOpositeTime(s,(*curve_it1).toSBasis()); double time2 = sat.getTime(curve_it2Fixed->toSBasis()); if(time1 <= time0){ time1 = time0; @@ -249,7 +271,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) endArcPoint = curve_it2Fixed->pointAt(times[2]-gapHelper); } if(times[1] == times[0]){ - startArcPoint = knotCurve1->pointAt(1-gapHelper); + startArcPoint = curve_it1->pointAt(times[0]+gapHelper); } double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; double k2 = distance(endArcPoint, curve_it2Fixed->initialPoint()) * K; @@ -289,7 +311,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) endArcPoint = curve_it2Fixed->pointAt(times[2]); } if(times[1] == times[0]){ - startArcPoint = knotCurve1->pointAt(1); + startArcPoint = curve_it1->pointAt(times[0]); } Line const x_line(Geom::Point(0,0),Geom::Point(1,0)); Line const angled_line(startArcPoint,endArcPoint); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index f5c4f14ea..149a2d743 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -43,6 +43,7 @@ public: private: EnumParam method; BoolParam flexible; + BoolParam mirrorKnots; Geom::Pointwise *pointwise; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 2c3d823a5..c00cdd8da 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -54,15 +54,17 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ return 0; } gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray[6] && !strarray[7]){ + if(strarray[8] && !strarray[9]){ sat->setSatelliteType(strarray[0]); sat->setIsTime(strncmp(strarray[1],"1",1) == 0); - sat->setActive(strncmp(strarray[2],"1",1) == 0); - sat->setHasMirror(strncmp(strarray[3],"1",1) == 0); - sat->setHidden(strncmp(strarray[4],"1",1) == 0); + sat->setIsClosing(strncmp(strarray[2],"1",1) == 0); + sat->setIsStart(strncmp(strarray[3],"1",1) == 0); + sat->setActive(strncmp(strarray[4],"1",1) == 0); + sat->setHasMirror(strncmp(strarray[5],"1",1) == 0); + sat->setHidden(strncmp(strarray[6],"1",1) == 0); double ammount,angle; - sp_svg_number_read_d(strarray[5], &ammount); - sp_svg_number_read_d(strarray[6], &angle); + sp_svg_number_read_d(strarray[7], &ammount); + sp_svg_number_read_d(strarray[8], &angle); sat->setAmmount(ammount); sat->setAngle(angle); g_strfreev (strarray); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 1a5823199..0be155f50 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -119,6 +119,10 @@ protected: str << "*"; str << nVector.second.getIsTime(); str << "*"; + str << nVector.second.getIsClosing(); + str << "*"; + str << nVector.second.getIsStart(); + str << "*"; str << nVector.second.getActive(); str << "*"; str << nVector.second.getHasMirror(); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index e6f0c03f9..7a35df28f 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -54,7 +54,9 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { for (unsigned int i = 0; i < _vector.size(); ++i) { - addKnotHolderEntitieMirrored(knotholder, desktop, item, i); + if(_vector[i].second.getHasMirror()){ + addKnotHolderEntitieMirrored(knotholder, desktop, item, i); + } const gchar *tip; tip = _("Fillet: Ctrl+Click toggle type, " "Shift+Click open dialog, " @@ -105,10 +107,20 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, boost::optional > d2_in = pointwise->getCurveIn(satellite); if(d2_in){ double mirrorTime = Geom::nearest_point(s, *d2_in); + double timeStart = 0; + std::vector satVector = pointwise->findPeviousSatellites(satellite.first,1); + if(satVector.size()>0){ + timeStart = satVector[0].getTime(*d2_in); + } + if(timeStart > mirrorTime){ + mirrorTime = timeStart; + } double size = satellite.second.toSize(mirrorTime, *d2_in); double lenght = Geom::length(*d2_in, Geom::EPSILON) - size; double time = satellite.second.toTime(lenght,pwd2[satellite.first]); + std::cout << time << "time\n"; s = pwd2[satellite.first].valueAt(time); + std::cout << s << "s\n"; satellite.second.setPosition(s,pwd2[satellite.first]); } } else { @@ -136,7 +148,26 @@ SatellitePairArrayParamKnotHolderEntity::knot_get() const tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); boost::optional > d2_in = pointwise->getCurveIn(satellite); if(d2_in){ - tmpPoint = (*d2_in).valueAt(satellite.second.getOpositeTime(*d2_in)); + double s = satellite.second.getAmmount(); + if(satellite.second.getIsTime()){ + s = satellite.second.toSize(s, pwd2[satellite.first]); + } + double t = satellite.second.getOpositeTime(s,*d2_in); + if(t > 1){ + t = 1; + } + if(t < 0){ + t = 0; + } + double timeStart = 0; + std::vector satVector = pointwise->findPeviousSatellites(satellite.first,1); + if(satVector.size()>0){ + timeStart = satVector[0].getTime(*d2_in); + } + if(timeStart > t){ + t = timeStart; + } + tmpPoint = (*d2_in).valueAt(t); } } else { tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); -- cgit v1.2.3 From ef1da924221c3ab94e0c7bedf580f4a930459aa4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 3 Mar 2015 00:11:38 +0100 Subject: added more fillet/chamfer properties (bzr r13645.1.28) --- src/2geom/satellite.h | 6 +- src/live_effects/lpe-fillet-chamfer.cpp | 312 +++++++++++++++++++--- src/live_effects/lpe-fillet-chamfer.h | 23 +- src/live_effects/parameter/satellitepairarray.cpp | 5 +- 4 files changed, 298 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index 7581e6e34..aa949a97c 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 d46d0f4ff..802340698 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -27,6 +27,8 @@ #include "helper/geom-curves.h" #include "helper/geom.h" #include "display/curve.h" +#include "ui/tools-switch.h" +#include <2geom/path-intersection.h> #include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -45,16 +47,37 @@ FMConverter(FilletMethodData, FM_END); LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this), + satellitepairarrayparam_values(_("pair_array_param"), _("pair_array_param"), "satellitepairarrayparam_values", &wr, this), + unit(_("Unit:"), _("Unit"), "unit", &wr, this), method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), + radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), + chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 3), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), - mirrorKnots(_("Mirror Knots"), _("Mirror Knots"), "mirrorKnots", &wr, this, true), + mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "mirror_knots", &wr, this, true), + only_selected(_("Change only selected nodes"), _("Change only selected nodes"), "only_selected", &wr, this, false), + use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), + hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), + ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), pointwise() { registerParameter(&satellitepairarrayparam_values); + registerParameter(&unit); registerParameter(&method); + registerParameter(&radius); + registerParameter(&chamfer_steps); registerParameter(&flexible); - registerParameter(&mirrorKnots); + registerParameter(&use_knot_distance); + registerParameter(&mirror_knots); + registerParameter(&ignore_radius_0); + registerParameter(&only_selected); + registerParameter(&hide_knots); + + radius.param_set_range(0., infinity()); + radius.param_set_increments(1, 1); + radius.param_set_digits(4); + chamfer_steps.param_set_range(1, 999); + chamfer_steps.param_set_increments(1, 1); + chamfer_steps.param_set_digits(0); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -108,7 +131,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, isClosing, isStart, active, mirrorKnots, hidden, 0.0, 0.0); + Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0); satellites.push_back(std::make_pair(counterTotal, satellite)); ++curve_it1; counter++; @@ -119,7 +142,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) bool isClosing = false; bool isStart = false; bool hidden = false; - Satellite satellite(F, flexible, isClosing, isStart, active, mirrorKnots, hidden, 0.0, 0.0); + Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0); satellites.push_back(std::make_pair(counterTotal, satellite)); } } @@ -132,6 +155,222 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } +Gtk::Widget *LPEFilletChamfer::newWidget() +{ + // use manage here, because after deletion of Effect object, others might + // still be pointing to this widget. + Gtk::VBox *vbox = Gtk::manage(new Gtk::VBox(Effect::newWidget())); + + vbox->set_border_width(5); + vbox->set_homogeneous(false); + vbox->set_spacing(2); + std::vector::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter *param = *it; + Gtk::Widget *widg = param->param_newWidget(); + if (param->param_key == "radius") { + Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateFillet)); + widg = widgRegistered; + if (widg) { + Gtk::HBox *scalarParameter = dynamic_cast(widg); + std::vector childList = scalarParameter->get_children(); + Gtk::Entry *entryWidg = dynamic_cast(childList[1]); + entryWidg->set_width_chars(6); + } + /*} else if (param->param_key == "chamfer_steps") { + Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamferSubdivisions)); + widg = widgRegistered; + if (widg) { + Gtk::HBox *scalarParameter = dynamic_cast(widg); + std::vector childList = scalarParameter->get_children(); + Gtk::Entry *entryWidg = dynamic_cast(childList[1]); + entryWidg->set_width_chars(3); + } + + } else if (param->param_key == "helper_size") { + Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); + */ + } else if (param->param_key == "only_selected") { + Gtk::manage(widg); + }/* else if (param->param_key == "ignore_radius_0") { + Gtk::manage(widg); + } + */ + Glib::ustring *tip = param->param_getTooltip(); + if (widg) { + vbox->pack_start(*widg, true, true, 2); + if (tip) { + widg->set_tooltip_text(*tip); + } else { + widg->set_tooltip_text(""); + widg->set_has_tooltip(false); + } + } + } + + ++it; + } + + Gtk::HBox *filletContainer = Gtk::manage(new Gtk::HBox(true, 0)); + Gtk::Button *fillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); + fillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::fillet)); + + filletContainer->pack_start(*fillet, true, true, 2); + Gtk::Button *inverseFillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); + inverseFillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseFillet)); + filletContainer->pack_start(*inverseFillet, true, true, 2); + + Gtk::HBox *chamferContainer = Gtk::manage(new Gtk::HBox(true, 0)); + Gtk::Button *chamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); + chamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamfer)); + + chamferContainer->pack_start(*chamfer, true, true, 2); + Gtk::Button *inverseChamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); + inverseChamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseChamfer)); + chamferContainer->pack_start(*inverseChamfer, true, true, 2); + + vbox->pack_start(*filletContainer, true, true, 2); + vbox->pack_start(*chamferContainer, true, true, 2); + + return vbox; +} + + +void LPEFilletChamfer::fillet() +{ + updateSatelliteType(F); +} + +void LPEFilletChamfer::inverseFillet() +{ + updateSatelliteType(IF); +} + +void LPEFilletChamfer::chamfer() +{ + updateSatelliteType(C); +} + +void LPEFilletChamfer::inverseChamfer() +{ + updateSatelliteType(IC); +} + +/* +double LPEFilletChamfer::len_to_rad(double A, std::pair satellite) +{ + Piecewise > pwd2 = pointwise->getPwd2(); + boost::optional > d2_in = pointwise->getCurveIn(satellite); + if(d2_in){ + Geom::D2 d2_out = pwd2[satellite.first]; + double time_in = satellite.second.getOpositeTime(A, *d2_in); + double time_out = satellite.second.toTime(A,d2_out); + Geom::Point startArcPoint = (*d2_in).valueAt(time_in); + Geom::Point endArcPoint = d2_out.valueAt(time_out); + Ray ray1(startArcPoint, (*d2_in).valueAt(1)); + Ray ray2(d2_out.valueAt(0), endArcPoint); + bool ccwToggle = cross((*d2_in).valueAt(1) - startArcPoint, endArcPoint - startArcPoint) < 0; + double distanceArc = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint)); + double angleBetween = angle_between(ray1, ray2, ccwToggle); + return distanceArc/sin(angleBetween/2.0); + } + return 0; +} +*/ + +double LPEFilletChamfer::rad_to_len(double A, std::pair satellite) +{ + double len = 0; + Piecewise > pwd2 = pointwise->getPwd2(); + boost::optional > d2_in = pointwise->getCurveIn(satellite); + if(d2_in){ + Geom::D2 d2_out = pwd2[satellite.first]; + Piecewise > offset_curve0 = Piecewise >(*d2_in)+rot90(unitVector(derivative((*d2_in))))*(A); + Piecewise > offset_curve1 = Piecewise >(d2_out)+rot90(unitVector(derivative(d2_out)))*(A); + Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; + Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; + Geom::Crossings cs = Geom::crossings(p0, p1); + if(cs.size() > 0){ + Point cp =p0(cs[0].ta); + double p0pt = nearest_point(cp, d2_out); + len = satellite.second.toSize(p0pt,d2_out); + } else { + if(A < 0){ + len = rad_to_len(A * -1, satellite); + } + } + } + return len; +} + + +void LPEFilletChamfer::refreshKnots() +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if (tools_isactive(desktop, TOOLS_NODES)) { + tools_switch(desktop, TOOLS_SELECT); + tools_switch(desktop, TOOLS_NODES); + } +} + +void LPEFilletChamfer::updateFillet() +{ + double power = 0; + if (!flexible) { + power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), *defaultUnit); + } else { + power = radius/100; + } + std::vector > satellites = pointwise->getSatellites(); + Piecewise > pwd2 = pointwise->getPwd2(); + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(ignore_radius_0 && it->second.getAmmount() == 0){ + continue; + } + if(only_selected){ + Geom::Point satPoint = pwd2.valueAt(it->first); + if(isNodePointSelected(satPoint)){ + it->second.setAmmount(power); + } + if(!use_knot_distance && !flexible){ + it->second.setAmmount(rad_to_len(power,*it)); + } + } else { + it->second.setAmmount(power); + if(!use_knot_distance && !flexible){ + it->second.setAmmount(rad_to_len(power,*it)); + } + } + } + pointwise->setSatellites(satellites); + satellitepairarrayparam_values.param_set_and_write_new_value(satellites); +} + +void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) +{ + std::vector > satellites = pointwise->getSatellites(); + Piecewise > pwd2 = pointwise->getPwd2(); + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(ignore_radius_0 && it->second.getAmmount() == 0){ + continue; + } + if(only_selected){ + Geom::Point satPoint = pwd2.valueAt(it->first); + if(isNodePointSelected(satPoint)){ + it->second.setSatelliteType(satellitetype); + } + } else { + it->second.setSatelliteType(satellitetype); + } + } + pointwise->setSatellites(satellites); + satellitepairarrayparam_values.param_set_and_write_new_value(satellites); +} + void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { SPLPEItem * splpeitem = const_cast(lpeItem); @@ -152,6 +391,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise->setSatellites(satellites); satellitepairarrayparam_values.set_pointwise(pointwise); bool changed = false; + bool refresh = false; for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(it->second.getIsTime() != flexible){ it->second.setIsTime(flexible); @@ -166,15 +406,25 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } changed = true; } - if(it->second.getHasMirror() != mirrorKnots){ - it->second.setHasMirror(mirrorKnots); + if(it->second.getHasMirror() != mirror_knots){ + it->second.setHasMirror(mirror_knots); changed = true; + refresh = true; + } + bool hide = !hide_knots; + if(it->second.getHidden() != hide){ + it->second.setHidden(hide); + changed = true; + refresh = true; } } if(changed){ pointwise->setSatellites(satellites); satellitepairarrayparam_values.param_set_and_write_new_value(satellites); } + if(refresh){ + refreshKnots(); + } } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -219,18 +469,18 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) return path_in; } std::vector satVector; - Satellite sat; + Satellite satellite; Curve *curve_it2Fixed = path_it->begin()->duplicate(); if(!path_it->closed() || curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); satVector = pointwise->findSatellites(counter+1,1); if(satVector.size()>0){ - sat = satVector[0]; + satellite = satVector[0]; } } else { satVector = pointwise->findSatellites(first,1); if(satVector.size()>0){ - sat = satVector[0]; + satellite = satVector[0]; } } if(first == counter){ @@ -241,12 +491,12 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } bool last = curve_it2 == curve_endit; - double s = sat.getAmmount(); - if(sat.getIsTime()){ - s = sat.toSize(s, curve_it2Fixed->toSBasis()); + double s = satellite.getAmmount(); + if(satellite.getIsTime()){ + s = satellite.toSize(s, curve_it2Fixed->toSBasis()); } - double time1 = sat.getOpositeTime(s,(*curve_it1).toSBasis()); - double time2 = sat.getTime(curve_it2Fixed->toSBasis()); + double time1 = satellite.getOpositeTime(s,(*curve_it1).toSBasis()); + double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); if(time1 <= time0){ time1 = time0; } @@ -254,10 +504,6 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) times.push_back(time0); times.push_back(time1); times.push_back(time2); - std::cout << ":::" << counter << ":::::::::::::::\n"; - std::cout << time0 << "::Time 0\n"; - std::cout << time1 << "::Time 1\n"; - std::cout << time2 << "::Time 2\n"; Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); if (counterCurves > 0) { knotCurve1->setInitial(path_out.finalPoint()); @@ -325,13 +571,8 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) path_out.append(*knotCurve1); } } - SatelliteType type = F; - type = sat.getSatelliteType(); - if(are_near(middle_point(startArcPoint,endArcPoint),curve_it1->finalPoint(), 0.0001)){ - // path_out.appendNew(endArcPoint); - } else if (type == C) { - /* - unsigned int chamferSubs = type-3000; + SatelliteType type = satellite.getSatelliteType(); + if (type == C) { Geom::Path path_chamfer; path_chamfer.start(path_out.finalPoint()); if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ @@ -339,16 +580,13 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } else { path_chamfer.appendNew(handle1, handle2, endArcPoint); } - double chamfer_stepsTime = 1.0/chamferSubs; - for(unsigned int i = 1; i < chamferSubs; i++){ + double chamfer_stepsTime = 1.0/chamfer_steps; + for(unsigned int i = 1; i < chamfer_steps; i++){ Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); path_out.appendNew(chamferStep); } path_out.appendNew(endArcPoint); - /*/ } else if (type == IC) { - /* - unsigned int chamferSubs = type-4000; Geom::Path path_chamfer; path_chamfer.start(path_out.finalPoint()); if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ @@ -357,13 +595,12 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) }else{ path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } - double chamfer_stepsTime = 1.0/chamferSubs; - for(unsigned int i = 1; i < chamferSubs; i++){ + double chamfer_stepsTime = 1.0/chamfer_steps; + for(unsigned int i = 1; i < chamfer_steps; i++){ Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); path_out.appendNew(chamferStep); } path_out.appendNew(endArcPoint); - */ } else if (type == IF) { if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ ccwToggle = ccwToggle?0:1; @@ -386,13 +623,6 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (path_it->closed() && last) { path_out.close(); } - /* - if(!path_it->closed() || curve_it2 != curve_endit){ - satellites[counter + 1] = std::make_pair(counter + 1, sat); - } else { - satellites[first] = std::make_pair(first, sat); - } - */ ++curve_it1; if (curve_it2 != curve_endit) { ++curve_it2; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 149a2d743..44c8b113f 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -15,6 +15,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/parameter/enum.h" +#include "live_effects/parameter/unit.h" #include "2geom/pointwise.h" #include "live_effects/parameter/satellitepairarray.h" #include "live_effects/effect.h" @@ -37,13 +38,31 @@ public: virtual std::vector doEffect_path(std::vector const &path_in); virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector const &path_in); - + virtual Gtk::Widget* newWidget(); + /*double len_to_rad(double A, std::pair sat);*/ + double rad_to_len(double A, std::pair satellite); + void updateSatelliteType(Geom::SatelliteType satellitetype); + void updateFillet(); + void refreshKnots(); + void chamfer(); + void inverseChamfer(); + void fillet(); + void inverseFillet(); + SatellitePairArrayParam satellitepairarrayparam_values; private: + UnitParam unit; EnumParam method; + ScalarParam radius; + ScalarParam chamfer_steps; BoolParam flexible; - BoolParam mirrorKnots; + BoolParam mirror_knots; + BoolParam only_selected; + BoolParam use_knot_distance; + BoolParam hide_knots; + BoolParam ignore_radius_0; + Geom::Pointwise *pointwise; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 7a35df28f..beda9ecbf 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -54,6 +54,9 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { for (unsigned int i = 0; i < _vector.size(); ++i) { + if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ + continue; + } if(_vector[i].second.getHasMirror()){ addKnotHolderEntitieMirrored(knotholder, desktop, item, i); } @@ -118,9 +121,7 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, double size = satellite.second.toSize(mirrorTime, *d2_in); double lenght = Geom::length(*d2_in, Geom::EPSILON) - size; double time = satellite.second.toTime(lenght,pwd2[satellite.first]); - std::cout << time << "time\n"; s = pwd2[satellite.first].valueAt(time); - std::cout << s << "s\n"; satellite.second.setPosition(s,pwd2[satellite.first]); } } else { -- cgit v1.2.3 From 60327dd47f6bbbb0d30c13c905117bd8b3be5e5d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 3 Mar 2015 23:54:42 +0100 Subject: added helper paths and fixed some bugs (bzr r13645.1.30) --- src/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 + src/live_effects/parameter/satellitepairarray.cpp | 87 +++++++++++++++++++++-- src/live_effects/parameter/satellitepairarray.h | 9 ++- 8 files changed, 134 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 3c359eddc..0115ea103 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 c7426dc9d..aa907d498 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 9c253523e..c216595dc 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 aa949a97c..48be13cc4 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 802340698..a8e2ea6b8 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -58,6 +58,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), + helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), pointwise() { registerParameter(&satellitepairarrayparam_values); @@ -65,6 +66,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : registerParameter(&method); registerParameter(&radius); registerParameter(&chamfer_steps); + registerParameter(&helper_size); registerParameter(&flexible); registerParameter(&use_knot_distance); registerParameter(&mirror_knots); @@ -78,6 +80,9 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : chamfer_steps.param_set_range(1, 999); chamfer_steps.param_set_increments(1, 1); chamfer_steps.param_set_digits(0); + helper_size.param_set_range(0, infinity()); + helper_size.param_set_increments(5, 5); + helper_size.param_set_digits(0); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -126,8 +131,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) bool active = true; bool hidden = false; if (counter==0) { - if (path_it->closed()) { - } else { + if (!path_it->closed()) { active = false; } } @@ -179,27 +183,12 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entryWidg = dynamic_cast(childList[1]); entryWidg->set_width_chars(6); } - /*} else if (param->param_key == "chamfer_steps") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamferSubdivisions)); - widg = widgRegistered; - if (widg) { - Gtk::HBox *scalarParameter = dynamic_cast(widg); - std::vector childList = scalarParameter->get_children(); - Gtk::Entry *entryWidg = dynamic_cast(childList[1]); - entryWidg->set_width_chars(3); - } - } else if (param->param_key == "helper_size") { Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); - */ } else if (param->param_key == "only_selected") { Gtk::manage(widg); - }/* else if (param->param_key == "ignore_radius_0") { - Gtk::manage(widg); } - */ Glib::ustring *tip = param->param_getTooltip(); if (widg) { vbox->pack_start(*widg, true, true, 2); @@ -211,7 +200,6 @@ Gtk::Widget *LPEFilletChamfer::newWidget() } } } - ++it; } @@ -285,24 +273,25 @@ double LPEFilletChamfer::len_to_rad(double A, std::pair sa double LPEFilletChamfer::rad_to_len(double A, std::pair satellite) { double len = 0; + std::cout << A << "A\n"; Piecewise > pwd2 = pointwise->getPwd2(); boost::optional > d2_in = pointwise->getCurveIn(satellite); if(d2_in){ + std::cout << satellite.first << "satellite.first\n"; + std::cout << "d2in\n"; Geom::D2 d2_out = pwd2[satellite.first]; - Piecewise > offset_curve0 = Piecewise >(*d2_in)+rot90(unitVector(derivative((*d2_in))))*(A); + Piecewise > offset_curve0 = Piecewise >(*d2_in)+rot90(unitVector(derivative(*d2_in)))*(A); Piecewise > offset_curve1 = Piecewise >(d2_out)+rot90(unitVector(derivative(d2_out)))*(A); Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; Geom::Crossings cs = Geom::crossings(p0, p1); if(cs.size() > 0){ Point cp =p0(cs[0].ta); + std::cout << cp << "cp\n"; double p0pt = nearest_point(cp, d2_out); len = satellite.second.toSize(p0pt,d2_out); - } else { - if(A < 0){ - len = rad_to_len(A * -1, satellite); - } } + std::cout << len << "len\n"; } return len; } @@ -328,21 +317,27 @@ void LPEFilletChamfer::updateFillet() std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(pointwise->findClosingSatellites(it->first).size() == 0 && it->second.getIsStart()){ + it->second.setAmmount(0); + continue; + } if(ignore_radius_0 && it->second.getAmmount() == 0){ continue; } if(only_selected){ Geom::Point satPoint = pwd2.valueAt(it->first); if(isNodePointSelected(satPoint)){ - it->second.setAmmount(power); - } - if(!use_knot_distance && !flexible){ - it->second.setAmmount(rad_to_len(power,*it)); + if(!use_knot_distance && !flexible){ + it->second.setAmmount(rad_to_len(power,*it)); + } else { + it->second.setAmmount(power); + } } } else { - it->second.setAmmount(power); if(!use_knot_distance && !flexible){ it->second.setAmmount(rad_to_len(power,*it)); + } else { + it->second.setAmmount(power); } } } @@ -384,12 +379,14 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(original_pathv)); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - //wating to recalculate - //recalculate_controlpoints_for_new_pwd2(pwd2_in); std::vector > satellites = satellitepairarrayparam_values.data(); - pointwise->setPwd2(pwd2_in); - pointwise->setSatellites(satellites); + pointwise = new Pointwise(pwd2_in,satellites); satellitepairarrayparam_values.set_pointwise(pointwise); + if(hide_knots){ + satellitepairarrayparam_values.set_helper_size(0); + } else { + satellitepairarrayparam_values.set_helper_size(helper_size); + } bool changed = false; bool refresh = false; for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { @@ -491,10 +488,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } bool last = curve_it2 == curve_endit; - double s = satellite.getAmmount(); - if(satellite.getIsTime()){ - s = satellite.toSize(s, curve_it2Fixed->toSBasis()); - } + double s = satellite.getSize(curve_it2Fixed->toSBasis()); double time1 = satellite.getOpositeTime(s,(*curve_it1).toSBasis()); double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); if(time1 <= time0){ diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 44c8b113f..c194d2edd 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -62,6 +62,7 @@ private: BoolParam use_knot_distance; BoolParam hide_knots; BoolParam ignore_radius_0; + ScalarParam helper_size; Geom::Pointwise *pointwise; diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index beda9ecbf..72a666dc2 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -31,6 +31,14 @@ SatellitePairArrayParam::SatellitePairArrayParam( knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; knot_color = 0x00ff0000; + /* + std::vector > satellites; + Geom::Path path; + path.start(Geom::Point(0,0)); + path.appendNew(Geom::Point(0,1)); + last_pointwise = new Pointwise(path.toPwSb(),satellites); + */ + last_pointwise = NULL; } SatellitePairArrayParam::~SatellitePairArrayParam() {} @@ -49,6 +57,74 @@ void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) last_pointwise = pointwise; } +void SatellitePairArrayParam::set_helper_size(int hs) +{ + helper_size = hs; + updateCanvasIndicators(); +} + +void SatellitePairArrayParam::updateCanvasIndicators() +{ + Geom::Piecewise > pwd2 = last_pointwise->getPwd2(); + hp.clear(); + bool mirrorPass = false; + for (unsigned int i = 0; i < _vector.size(); ++i) { + if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ + continue; + } + double pos = 0; + if(pwd2.size() <= _vector[i].first){ + break; + } + Geom::D2 d2 = pwd2[_vector[i].first]; + if(mirrorPass == true){ + double size = _vector[i].second.getSize(pwd2[_vector[i].first]); + boost::optional > curve_in = last_pointwise->getCurveIn(_vector[i]); + if(curve_in){ + d2 = *curve_in; + pos = _vector[i].second.getOpositeTime(size,*curve_in); + } + } else { + pos = _vector[i].second.getTime(pwd2[_vector[i].first]); + } + if (pos == 0) { + continue; + } + Geom::Point ptA = d2.valueAt(pos); + Geom::Point derivA = unit_vector(derivative(d2).valueAt(pos)); + Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); + derivA = derivA * rot; + Geom::Point C = ptA - derivA * helper_size; + Geom::Point D = ptA + derivA * helper_size; + Geom::Ray ray1(C, D); + char const * svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + Geom::Affine aff = Geom::Affine(); + aff *= Geom::Scale(helper_size); + if(mirrorPass == true){ + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); + } else { + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); + } + pathv *= aff; + pathv += d2.valueAt(pos); + hp.push_back(pathv[0]); + hp.push_back(pathv[1]); + if(_vector[i].second.getHasMirror() && mirrorPass == false){ + mirrorPass = true; + i--; + } else { + mirrorPass = false; + } + } +} + +void SatellitePairArrayParam::addCanvasIndicators( + SPLPEItem const */*lpeitem*/, std::vector &hp_vec) +{ + hp_vec.push_back(hp); +} + void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) @@ -103,6 +179,9 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } + if( _pparam->last_pointwise == NULL){ + return; + } std::pair satellite = _pparam->_vector.at(index); Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); @@ -143,16 +222,16 @@ SatellitePairArrayParamKnotHolderEntity::knot_get() const index = _index-_pparam->_vector.size(); } std::pair satellite = _pparam->_vector.at(index); + if( _pparam->last_pointwise == NULL){ + return Geom::Point(0,0); + } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); if( _index >= _pparam->_vector.size()){ tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); boost::optional > d2_in = pointwise->getCurveIn(satellite); if(d2_in){ - double s = satellite.second.getAmmount(); - if(satellite.second.getIsTime()){ - s = satellite.second.toSize(s, pwd2[satellite.first]); - } + double s = satellite.second.getSize(pwd2[satellite.first]); double t = satellite.second.getOpositeTime(s,*d2_in); if(t > 1){ t = 1; diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index dde844fd1..1ecc1fee6 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -44,11 +44,14 @@ public: void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); + virtual void set_helper_size(int hs); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + virtual void addKnotHolderEntitieMirrored(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, int i); + virtual void addCanvasIndicators(SPLPEItem const *lpeitem,std::vector &hp_vec); virtual bool providesKnotHolderEntities() const { return true; } - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - virtual void addKnotHolderEntitieMirrored(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, int i); + virtual void updateCanvasIndicators(); void set_pointwise(Geom::Pointwise *pointwise); friend class SatellitePairArrayParamKnotHolderEntity; @@ -59,6 +62,8 @@ private: SPKnotShapeType knot_shape; SPKnotModeType knot_mode; guint32 knot_color; + Geom::PathVector hp; + int helper_size; Geom::Pointwise *last_pointwise; -- cgit v1.2.3 From 885ed9addb9a67398e74176fd541c3415c5f44d8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 4 Mar 2015 18:04:02 +0100 Subject: Fix radian to lenght conversion and minior bugs (bzr r13645.1.31) --- src/live_effects/lpe-fillet-chamfer.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index a8e2ea6b8..786945cd0 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -145,7 +145,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) bool active = false; bool isClosing = false; bool isStart = false; - bool hidden = false; + bool hidden = true; Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0); satellites.push_back(std::make_pair(counterTotal, satellite)); } @@ -290,6 +290,10 @@ double LPEFilletChamfer::rad_to_len(double A, std::pair sa std::cout << cp << "cp\n"; double p0pt = nearest_point(cp, d2_out); len = satellite.second.toSize(p0pt,d2_out); + } else { + if(A > 0){ + len = rad_to_len(A * -1, satellite); + } } std::cout << len << "len\n"; } @@ -491,6 +495,10 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double s = satellite.getSize(curve_it2Fixed->toSBasis()); double time1 = satellite.getOpositeTime(s,(*curve_it1).toSBasis()); double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); + if(!satellite.getActive()){ + time1 = 1; + time0 = 0; + } if(time1 <= time0){ time1 = time0; } -- cgit v1.2.3 From 1db09cce6114c1b2d95ac77b00672caad0447b29 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 4 Mar 2015 23:42:59 +0100 Subject: All features done, only need piecewise update function (bzr r13645.1.33) --- src/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 +- src/live_effects/parameter/satellitepairarray.cpp | 161 ++++++++++- src/live_effects/parameter/satellitepairarray.h | 12 +- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 313 ++++++++++++++++++++++ src/ui/dialog/lpe-fillet-chamfer-properties.h | 118 ++++++++ 12 files changed, 763 insertions(+), 117 deletions(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 0115ea103..1d1c69cee 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 aa907d498..b6bd4c4fd 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 c216595dc..22c3c8bed 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 48be13cc4..4b0797620 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 786945cd0..118a89ead 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -28,7 +28,6 @@ #include "helper/geom.h" #include "display/curve.h" #include "ui/tools-switch.h" -#include <2geom/path-intersection.h> #include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -97,7 +96,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int counterTotal = 0; - std::vector > satellites; + std::vector > satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; @@ -119,6 +118,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Path::const_iterator curve_end = curve_endit; --curve_end; int counter = 0; + unsigned int steps = 0; while (curve_it1 != curve_endit) { bool isStart = false; if(counter == 0){ @@ -135,7 +135,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0); + Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0, steps); satellites.push_back(std::make_pair(counterTotal, satellite)); ++curve_it1; counter++; @@ -146,7 +146,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) bool isClosing = false; bool isStart = false; bool hidden = true; - Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0); + Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0, steps); satellites.push_back(std::make_pair(counterTotal, satellite)); } } @@ -175,7 +175,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Widget *widg = param->param_newWidget(); if (param->param_key == "radius") { Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateFillet)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmmount)); widg = widgRegistered; if (widg) { Gtk::HBox *scalarParameter = dynamic_cast(widg); @@ -183,6 +183,16 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entryWidg = dynamic_cast(childList[1]); entryWidg->set_width_chars(6); } + } else if (param->param_key == "chamfer_steps") { + Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateChamferSteps)); + widg = widgRegistered; + if (widg) { + Gtk::HBox *scalarParameter = dynamic_cast(widg); + std::vector childList = scalarParameter->get_children(); + Gtk::Entry *entryWidg = dynamic_cast(childList[1]); + entryWidg->set_width_chars(3); + } } else if (param->param_key == "helper_size") { Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); @@ -248,59 +258,6 @@ void LPEFilletChamfer::inverseChamfer() updateSatelliteType(IC); } -/* -double LPEFilletChamfer::len_to_rad(double A, std::pair satellite) -{ - Piecewise > pwd2 = pointwise->getPwd2(); - boost::optional > d2_in = pointwise->getCurveIn(satellite); - if(d2_in){ - Geom::D2 d2_out = pwd2[satellite.first]; - double time_in = satellite.second.getOpositeTime(A, *d2_in); - double time_out = satellite.second.toTime(A,d2_out); - Geom::Point startArcPoint = (*d2_in).valueAt(time_in); - Geom::Point endArcPoint = d2_out.valueAt(time_out); - Ray ray1(startArcPoint, (*d2_in).valueAt(1)); - Ray ray2(d2_out.valueAt(0), endArcPoint); - bool ccwToggle = cross((*d2_in).valueAt(1) - startArcPoint, endArcPoint - startArcPoint) < 0; - double distanceArc = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint)); - double angleBetween = angle_between(ray1, ray2, ccwToggle); - return distanceArc/sin(angleBetween/2.0); - } - return 0; -} -*/ - -double LPEFilletChamfer::rad_to_len(double A, std::pair satellite) -{ - double len = 0; - std::cout << A << "A\n"; - Piecewise > pwd2 = pointwise->getPwd2(); - boost::optional > d2_in = pointwise->getCurveIn(satellite); - if(d2_in){ - std::cout << satellite.first << "satellite.first\n"; - std::cout << "d2in\n"; - Geom::D2 d2_out = pwd2[satellite.first]; - Piecewise > offset_curve0 = Piecewise >(*d2_in)+rot90(unitVector(derivative(*d2_in)))*(A); - Piecewise > offset_curve1 = Piecewise >(d2_out)+rot90(unitVector(derivative(d2_out)))*(A); - Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0]; - Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0]; - Geom::Crossings cs = Geom::crossings(p0, p1); - if(cs.size() > 0){ - Point cp =p0(cs[0].ta); - std::cout << cp << "cp\n"; - double p0pt = nearest_point(cp, d2_out); - len = satellite.second.toSize(p0pt,d2_out); - } else { - if(A > 0){ - len = rad_to_len(A * -1, satellite); - } - } - std::cout << len << "len\n"; - } - return len; -} - - void LPEFilletChamfer::refreshKnots() { SPDesktop *desktop = SP_ACTIVE_DESKTOP; @@ -310,7 +267,7 @@ void LPEFilletChamfer::refreshKnots() } } -void LPEFilletChamfer::updateFillet() +void LPEFilletChamfer::updateAmmount() { double power = 0; if (!flexible) { @@ -318,9 +275,9 @@ void LPEFilletChamfer::updateFillet() } else { power = radius/100; } - std::vector > satellites = pointwise->getSatellites(); + std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(pointwise->findClosingSatellites(it->first).size() == 0 && it->second.getIsStart()){ it->second.setAmmount(0); continue; @@ -332,14 +289,14 @@ void LPEFilletChamfer::updateFillet() Geom::Point satPoint = pwd2.valueAt(it->first); if(isNodePointSelected(satPoint)){ if(!use_knot_distance && !flexible){ - it->second.setAmmount(rad_to_len(power,*it)); + it->second.setAmmount(pointwise->rad_to_len(power,*it)); } else { it->second.setAmmount(power); } } } else { if(!use_knot_distance && !flexible){ - it->second.setAmmount(rad_to_len(power,*it)); + it->second.setAmmount(pointwise->rad_to_len(power,*it)); } else { it->second.setAmmount(power); } @@ -349,11 +306,32 @@ void LPEFilletChamfer::updateFillet() satellitepairarrayparam_values.param_set_and_write_new_value(satellites); } +void LPEFilletChamfer::updateChamferSteps() +{ + std::vector > satellites = pointwise->getSatellites(); + Piecewise > pwd2 = pointwise->getPwd2(); + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(ignore_radius_0 && it->second.getAmmount() == 0){ + continue; + } + if(only_selected){ + Geom::Point satPoint = pwd2.valueAt(it->first); + if(isNodePointSelected(satPoint)){ + it->second.setSteps(chamfer_steps); + } + } else { + it->second.setSteps(chamfer_steps); + } + } + pointwise->setSatellites(satellites); + satellitepairarrayparam_values.param_set_and_write_new_value(satellites); +} + void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) { - std::vector > satellites = pointwise->getSatellites(); + std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(ignore_radius_0 && it->second.getAmmount() == 0){ continue; } @@ -383,7 +361,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(original_pathv)); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector > satellites = satellitepairarrayparam_values.data(); + std::vector > satellites = satellitepairarrayparam_values.data(); pointwise = new Pointwise(pwd2_in,satellites); satellitepairarrayparam_values.set_pointwise(pointwise); if(hide_knots){ @@ -391,9 +369,12 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { satellitepairarrayparam_values.set_helper_size(helper_size); } + satellitepairarrayparam_values.set_document_unit(defaultUnit); + satellitepairarrayparam_values.set_use_distance(use_knot_distance); + satellitepairarrayparam_values.set_unit(unit.get_abbreviation()); bool changed = false; bool refresh = false; - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(it->second.getIsTime() != flexible){ it->second.setIsTime(flexible); double ammount = it->second.getAmmount(); @@ -574,6 +555,10 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } } SatelliteType type = satellite.getSatelliteType(); + unsigned int steps = satellite.getSteps(); + if(steps < 1){ + steps = 1; + } if (type == C) { Geom::Path path_chamfer; path_chamfer.start(path_out.finalPoint()); @@ -582,8 +567,8 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } else { path_chamfer.appendNew(handle1, handle2, endArcPoint); } - double chamfer_stepsTime = 1.0/chamfer_steps; - for(unsigned int i = 1; i < chamfer_steps; i++){ + double chamfer_stepsTime = 1.0/steps; + for(unsigned int i = 1; i < steps; i++){ Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); path_out.appendNew(chamferStep); } @@ -597,8 +582,8 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) }else{ path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } - double chamfer_stepsTime = 1.0/chamfer_steps; - for(unsigned int i = 1; i < chamfer_steps; i++){ + double chamfer_stepsTime = 1.0/steps; + for(unsigned int i = 1; i < steps; i++){ Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); path_out.appendNew(chamferStep); } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index c194d2edd..56db6305e 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -40,9 +40,9 @@ public: virtual void adjustForNewPath(std::vector const &path_in); virtual Gtk::Widget* newWidget(); /*double len_to_rad(double A, std::pair sat);*/ - double rad_to_len(double A, std::pair satellite); void updateSatelliteType(Geom::SatelliteType satellitetype); - void updateFillet(); + void updateChamferSteps(); + void updateAmmount(); void refreshKnots(); void chamfer(); void inverseChamfer(); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index c00cdd8da..e4c480d93 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -54,7 +54,7 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ return 0; } gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray[8] && !strarray[9]){ + if(strarray[9] && !strarray[10]){ sat->setSatelliteType(strarray[0]); sat->setIsTime(strncmp(strarray[1],"1",1) == 0); sat->setIsClosing(strncmp(strarray[2],"1",1) == 0); @@ -63,10 +63,14 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ sat->setHasMirror(strncmp(strarray[5],"1",1) == 0); sat->setHidden(strncmp(strarray[6],"1",1) == 0); double ammount,angle; + float stepsTmp; sp_svg_number_read_d(strarray[7], &ammount); sp_svg_number_read_d(strarray[8], &angle); + sp_svg_number_read_f(strarray[9], &stepsTmp); + unsigned int steps = (unsigned int)stepsTmp; sat->setAmmount(ammount); sat->setAngle(angle); + sat->setSteps(steps); g_strfreev (strarray); return 1; } @@ -75,12 +79,12 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ } template <> -std::pair -ArrayParam >::readsvg(const gchar * str) +std::pair +ArrayParam >::readsvg(const gchar * str) { gchar ** strarray = g_strsplit(str, ",", 2); double index; - std::pair result; + std::pair result; unsigned int success = (int)sp_svg_number_read_d(strarray[0], &index); Geom::Satellite sat; success += sp_svg_satellite_read_d(strarray[1], &sat); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 0be155f50..d28576fce 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -112,7 +112,7 @@ protected: str << nVector; } - void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { + void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { str << nVector.first; str << ","; str << nVector.second.getSatelliteTypeGchar(); @@ -132,6 +132,8 @@ protected: str << nVector.second.getAmmount(); str << "*"; str << nVector.second.getAngle(); + str << "*"; + str << nVector.second.getSteps(); } StorageType readsvg(const gchar * str); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 72a666dc2..ffd04e14c 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -9,6 +9,7 @@ */ #include "knotholder.h" +#include "ui/dialog/lpe-fillet-chamfer-properties.h" #include "live_effects/parameter/satellitepairarray.h" #include "sp-lpe-item.h" // TODO due to internal breakage in glibmm headers, @@ -26,18 +27,14 @@ SatellitePairArrayParam::SatellitePairArrayParam( const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayParam >(label, tip, key, wr, effect, 0) + : ArrayParam >(label, tip, key, wr, effect, 0) { knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; knot_color = 0x00ff0000; - /* - std::vector > satellites; - Geom::Path path; - path.start(Geom::Point(0,0)); - path.appendNew(Geom::Point(0,1)); - last_pointwise = new Pointwise(path.toPwSb(),satellites); - */ + helper_size = 0; + use_distance = false; + last_pointwise = NULL; } @@ -57,6 +54,21 @@ void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) last_pointwise = pointwise; } +void SatellitePairArrayParam::set_document_unit(Glib::ustring const * value_document_unit) +{ + documentUnit = value_document_unit; +} + +void SatellitePairArrayParam::set_use_distance(bool use_knot_distance ) +{ + use_distance = use_knot_distance; +} + +void SatellitePairArrayParam::set_unit(const gchar *abbr) +{ + unit = abbr; +} + void SatellitePairArrayParam::set_helper_size(int hs) { helper_size = hs; @@ -73,7 +85,7 @@ void SatellitePairArrayParam::updateCanvasIndicators() continue; } double pos = 0; - if(pwd2.size() <= _vector[i].first){ + if(pwd2.size() <= (unsigned)_vector[i].first){ break; } Geom::D2 d2 = pwd2[_vector[i].first]; @@ -136,10 +148,26 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, if(_vector[i].second.getHasMirror()){ addKnotHolderEntitieMirrored(knotholder, desktop, item, i); } + using namespace Geom; + SatelliteType type = _vector[i].second.getSatelliteType(); const gchar *tip; - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); + if (type == C){ + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IC) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IF) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } SatellitePairArrayParamKnotHolderEntity *e = new SatellitePairArrayParamKnotHolderEntity(this, i); e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), @@ -152,8 +180,26 @@ void SatellitePairArrayParam::addKnotHolderEntitieMirrored(KnotHolder *knotholde SPDesktop *desktop, SPItem *item, int i) { + using namespace Geom; + SatelliteType type = _vector[i].second.getSatelliteType(); const gchar *tip; - tip = _("Mirror ppp"); + if (type == C){ + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IC) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IF) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } SatellitePairArrayParamKnotHolderEntity *e = new SatellitePairArrayParamKnotHolderEntity(this, i + _vector.size()); e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), @@ -257,6 +303,95 @@ SatellitePairArrayParamKnotHolderEntity::knot_get() const } +void SatellitePairArrayParamKnotHolderEntity::knot_click(guint state) +{ + int index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + if (state & GDK_CONTROL_MASK) { + if (state & GDK_MOD1_MASK) { + _pparam->_vector.at(index).second.setAmmount(0.0); + _pparam->param_set_and_write_new_value(_pparam->_vector); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + }else{ + using namespace Geom; + SatelliteType type = _pparam->_vector.at(index).second.getSatelliteType(); + switch(type){ + case F: + type = IF; + break; + case IF: + type = C; + break; + case C: + type = IC; + break; + default: + type = F; + break; + } + _pparam->_vector.at(index).second.setSatelliteType(type); + _pparam->param_set_and_write_new_value(_pparam->_vector); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + const gchar *tip; + if (type == C){ + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IC) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IF) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } + this->knot->tip = g_strdup(tip); + this->knot->show(); + } + } else if (state & GDK_SHIFT_MASK) { + double ammount = _pparam->_vector.at(index).second.getAmmount(); + if(!_pparam->use_distance && !_pparam->_vector.at(index).second.getIsTime()){ + ammount = _pparam->last_pointwise->len_to_rad(ammount, _pparam->_vector.at(index)); + } + boost::optional > d2_in = _pparam->last_pointwise->getCurveIn(_pparam->_vector.at(index)); + bool aprox = false; + D2 d2_out = _pparam->last_pointwise->getPwd2()[index]; + if(d2_in){ + aprox = ((*d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; + } + Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( + this->desktop, ammount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index).second); + + } +} + +void SatellitePairArrayParamKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) +{ + int index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + double ammount = satellite.getAmmount(); + if(!_pparam->use_distance && !satellite.getIsTime()){ + ammount = _pparam->last_pointwise->rad_to_len(ammount, _pparam->_vector.at(index)); + } + satellite.setAmmount(ammount); + _pparam->_vector.at(index).second = satellite; + this->parent_holder->knot_ungrabbed_handler(this->knot, 0); + _pparam->param_set_and_write_new_value(_pparam->_vector); + SPLPEItem * splpeitem = dynamic_cast(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); + } +} + } /* namespace LivePathEffect */ } /* namespace Inkscape */ diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index 1ecc1fee6..21fb0fbd8 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -29,7 +29,7 @@ namespace LivePathEffect { class SatellitePairArrayParamKnotHolderEntity; -class SatellitePairArrayParam : public ArrayParam > { +class SatellitePairArrayParam : public ArrayParam > { public: SatellitePairArrayParam(const Glib::ustring &label, const Glib::ustring &tip, @@ -51,6 +51,9 @@ public: virtual bool providesKnotHolderEntities() const { return true; } + void set_document_unit(Glib::ustring const * value_document_unit); + void set_use_distance(bool use_knot_distance ); + void set_unit(const gchar *abbr); virtual void updateCanvasIndicators(); void set_pointwise(Geom::Pointwise *pointwise); friend class SatellitePairArrayParamKnotHolderEntity; @@ -64,7 +67,9 @@ private: guint32 knot_color; Geom::PathVector hp; int helper_size; - + bool use_distance; + const gchar *unit; + Glib::ustring const * documentUnit; Geom::Pointwise *last_pointwise; }; @@ -76,7 +81,8 @@ public: virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); virtual Geom::Point knot_get() const; - + virtual void knot_click(guint state); + void knot_set_offset(Geom::Satellite); /** Checks whether the index falls within the size of the parameter's vector */ bool valid_index(unsigned int index) const { return (_pparam->_vector.size() > index); diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index e69de29bb..fe0deba57 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 e69de29bb..63215d17c 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 +// : -- cgit v1.2.3 From 62ebac099d8fa013e34a773c0fe3aee56b5a5758 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 7 Mar 2015 13:55:16 +0100 Subject: finish helper paths and beter handle of fillet/chamfer overflow. Also make the satellitepairarray LPE parameter usable for other pointwise effects, not only to fillet chamfer (bzr r13645.1.35) --- src/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 +- src/live_effects/parameter/satellitepairarray.cpp | 217 +++++++++++++--------- src/live_effects/parameter/satellitepairarray.h | 16 +- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 20 +- src/ui/dialog/lpe-fillet-chamfer-properties.h | 14 +- 11 files changed, 222 insertions(+), 161 deletions(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 1d1c69cee..3b182916a 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 22c3c8bed..3420db7f6 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 4b0797620..d14a98a7f 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 118a89ead..d979171be 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -79,7 +79,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : chamfer_steps.param_set_range(1, 999); chamfer_steps.param_set_increments(1, 1); chamfer_steps.param_set_digits(0); - helper_size.param_set_range(0, infinity()); + helper_size.param_set_range(0, 999); helper_size.param_set_increments(5, 5); helper_size.param_set_digits(0); } @@ -175,7 +175,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Widget *widg = param->param_newWidget(); if (param->param_key == "radius") { Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmmount)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); widg = widgRegistered; if (widg) { Gtk::HBox *scalarParameter = dynamic_cast(widg); @@ -267,7 +267,7 @@ void LPEFilletChamfer::refreshKnots() } } -void LPEFilletChamfer::updateAmmount() +void LPEFilletChamfer::updateAmount() { double power = 0; if (!flexible) { @@ -279,26 +279,26 @@ void LPEFilletChamfer::updateAmmount() Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(pointwise->findClosingSatellites(it->first).size() == 0 && it->second.getIsStart()){ - it->second.setAmmount(0); + it->second.setAmount(0); continue; } - if(ignore_radius_0 && it->second.getAmmount() == 0){ + if(ignore_radius_0 && it->second.getAmount() == 0){ continue; } if(only_selected){ Geom::Point satPoint = pwd2.valueAt(it->first); if(isNodePointSelected(satPoint)){ if(!use_knot_distance && !flexible){ - it->second.setAmmount(pointwise->rad_to_len(power,*it)); + it->second.setAmount(pointwise->rad_to_len(power,*it)); } else { - it->second.setAmmount(power); + it->second.setAmount(power); } } } else { if(!use_knot_distance && !flexible){ - it->second.setAmmount(pointwise->rad_to_len(power,*it)); + it->second.setAmount(pointwise->rad_to_len(power,*it)); } else { - it->second.setAmmount(power); + it->second.setAmount(power); } } } @@ -311,7 +311,7 @@ void LPEFilletChamfer::updateChamferSteps() std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->second.getAmmount() == 0){ + if(ignore_radius_0 && it->second.getAmount() == 0){ continue; } if(only_selected){ @@ -332,7 +332,7 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->second.getAmmount() == 0){ + if(ignore_radius_0 && it->second.getAmount() == 0){ continue; } if(only_selected){ @@ -358,33 +358,40 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if(path){ c = path->get_original_curve(); } + //fillet chamfer specific calls + satellitepairarrayparam_values.set_document_unit(defaultUnit); + satellitepairarrayparam_values.set_use_distance(use_knot_distance); + satellitepairarrayparam_values.set_unit(unit.get_abbreviation()); + //mandatory call + satellitepairarrayparam_values.set_effect_type(this->effectType()); + PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(original_pathv)); + Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); std::vector > satellites = satellitepairarrayparam_values.data(); pointwise = new Pointwise(pwd2_in,satellites); + + //mandatory call satellitepairarrayparam_values.set_pointwise(pointwise); + //optional call if(hide_knots){ satellitepairarrayparam_values.set_helper_size(0); } else { satellitepairarrayparam_values.set_helper_size(helper_size); } - satellitepairarrayparam_values.set_document_unit(defaultUnit); - satellitepairarrayparam_values.set_use_distance(use_knot_distance); - satellitepairarrayparam_values.set_unit(unit.get_abbreviation()); bool changed = false; bool refresh = false; for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(it->second.getIsTime() != flexible){ it->second.setIsTime(flexible); - double ammount = it->second.getAmmount(); + double amount = it->second.getAmount(); D2 d2_in = pwd2_in[it->first]; if(it->second.getIsTime()){ - double time = it->second.toTime(ammount,d2_in); - it->second.setAmmount(time); + double time = it->second.toTime(amount,d2_in); + it->second.setAmount(time); } else { - double size = it->second.toSize(ammount,d2_in); - it->second.setAmmount(size); + double size = it->second.toSize(amount,d2_in); + it->second.setAmount(size); } changed = true; } @@ -483,6 +490,10 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if(time1 <= time0){ time1 = time0; } + std::cout << counter << ":::::::::::::::::::::::::::::\n"; + std::cout << time0 << "time0\n"; + std::cout << time1 << "time1\n"; + std::cout << time2 << "time2\n"; std::vector times; times.push_back(time0); times.push_back(time1); @@ -549,7 +560,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) Coord rx = radius; Coord ry = rx; if (times[1] != 1) { - if (times[1] != times[0] || times[1] == times[0] == 1) { + if (times[1] != times[0] || times[1] == times[0] == 1 ) { if(!knotCurve1->isDegenerate()){ path_out.append(*knotCurve1); } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 56db6305e..3d22216d4 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -42,7 +42,7 @@ public: /*double len_to_rad(double A, std::pair sat);*/ void updateSatelliteType(Geom::SatelliteType satellitetype); void updateChamferSteps(); - void updateAmmount(); + void updateAmount(); void refreshKnots(); void chamfer(); void inverseChamfer(); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index e4c480d93..e8a1b9532 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -62,13 +62,13 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ sat->setActive(strncmp(strarray[4],"1",1) == 0); sat->setHasMirror(strncmp(strarray[5],"1",1) == 0); sat->setHidden(strncmp(strarray[6],"1",1) == 0); - double ammount,angle; + double amount,angle; float stepsTmp; - sp_svg_number_read_d(strarray[7], &ammount); + sp_svg_number_read_d(strarray[7], &amount); sp_svg_number_read_d(strarray[8], &angle); sp_svg_number_read_f(strarray[9], &stepsTmp); unsigned int steps = (unsigned int)stepsTmp; - sat->setAmmount(ammount); + sat->setAmount(amount); sat->setAngle(angle); sat->setSteps(steps); g_strfreev (strarray); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index d28576fce..a6e797d4e 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -129,7 +129,7 @@ protected: str << "*"; str << nVector.second.getHidden(); str << "*"; - str << nVector.second.getAmmount(); + str << nVector.second.getAmount(); str << "*"; str << nVector.second.getAngle(); str << "*"; diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index ffd04e14c..9c2c1f93b 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -34,7 +34,7 @@ SatellitePairArrayParam::SatellitePairArrayParam( knot_color = 0x00ff0000; helper_size = 0; use_distance = false; - + _effectType = FILLET_CHAMFER; last_pointwise = NULL; } @@ -69,37 +69,61 @@ void SatellitePairArrayParam::set_unit(const gchar *abbr) unit = abbr; } +void SatellitePairArrayParam::set_effect_type(EffectType et) +{ + _effectType = et; +} + void SatellitePairArrayParam::set_helper_size(int hs) { helper_size = hs; updateCanvasIndicators(); } -void SatellitePairArrayParam::updateCanvasIndicators() +void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) { + if( last_pointwise == NULL){ + return; + } Geom::Piecewise > pwd2 = last_pointwise->getPwd2(); - hp.clear(); - bool mirrorPass = false; + if( mirror == true){ + hp.clear(); + } for (unsigned int i = 0; i < _vector.size(); ++i) { if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ continue; } + if((!_vector[i].second.getHasMirror() && mirror == true) || _vector[i].second.getAmount() == 0){ + continue; + } double pos = 0; if(pwd2.size() <= (unsigned)_vector[i].first){ break; } Geom::D2 d2 = pwd2[_vector[i].first]; - if(mirrorPass == true){ - double size = _vector[i].second.getSize(pwd2[_vector[i].first]); - boost::optional > curve_in = last_pointwise->getCurveIn(_vector[i]); + bool overflow = false; + double size_out = _vector[i].second.getSize(pwd2[_vector[i].first]); + double lenght_out = Geom::length(pwd2[_vector[i].first], Geom::EPSILON); + double lenght_in = 0; + boost::optional > curve_in = last_pointwise->getCurveIn(_vector[i]); + if(curve_in){ + lenght_in = Geom::length(*curve_in, Geom::EPSILON); + } + if(mirror == true){ if(curve_in){ d2 = *curve_in; - pos = _vector[i].second.getOpositeTime(size,*curve_in); + pos = _vector[i].second.getOpositeTime(size_out,*curve_in); + if(lenght_out < size_out){ + overflow = true; + } } } else { pos = _vector[i].second.getTime(pwd2[_vector[i].first]); + if(lenght_in < size_out){ + overflow = true; + } } - if (pos == 0) { + if (pos <= 0 || pos >= 1) { continue; } Geom::Point ptA = d2.valueAt(pos); @@ -113,7 +137,7 @@ void SatellitePairArrayParam::updateCanvasIndicators() Geom::PathVector pathv = sp_svg_read_pathv(svgd); Geom::Affine aff = Geom::Affine(); aff *= Geom::Scale(helper_size); - if(mirrorPass == true){ + if(mirror == true){ aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); } else { aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); @@ -122,13 +146,40 @@ void SatellitePairArrayParam::updateCanvasIndicators() pathv += d2.valueAt(pos); hp.push_back(pathv[0]); hp.push_back(pathv[1]); - if(_vector[i].second.getHasMirror() && mirrorPass == false){ - mirrorPass = true; - i--; - } else { - mirrorPass = false; + if(overflow){ + double diameter = helper_size; + if(helper_size == 0){ + diameter = 15; + char const * svgd; + svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + pathv *= Geom::Scale (diameter); + pathv += ptA-Geom::Point(diameter * 0.35,diameter * 0.35); + hp.push_back(pathv[0]); + } else { + char const * svgd; + svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A 1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 0 -1.32 z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + aff = Geom::Affine(); + aff *= Geom::Scale(helper_size/2.0); + if(mirror == true){ + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); + } else { + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); + } + pathv *= aff; + pathv += d2.valueAt(pos); + hp.push_back(pathv[0]); + } } } + if( mirror == true){ + updateCanvasIndicators(false); + } +} +void SatellitePairArrayParam::updateCanvasIndicators() +{ + updateCanvasIndicators(true); } void SatellitePairArrayParam::addCanvasIndicators( @@ -139,76 +190,62 @@ void SatellitePairArrayParam::addCanvasIndicators( void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item) + SPItem *item, + bool mirror) { for (unsigned int i = 0; i < _vector.size(); ++i) { if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ continue; } - if(_vector[i].second.getHasMirror()){ - addKnotHolderEntitieMirrored(knotholder, desktop, item, i); + if(!_vector[i].second.getHasMirror() && mirror == true){ + continue; + } + int iPlus = i; + if( mirror == true){ + iPlus = i + _vector.size(); } using namespace Geom; SatelliteType type = _vector[i].second.getSatelliteType(); - const gchar *tip; - if (type == C){ - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IC) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IF) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); + //IF is for filletChamfer effect... + if(_effectType == FILLET_CHAMFER){ + const gchar *tip; + if (type == C){ + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IC) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IF) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } + FilletChamferKnotHolderEntity *e = + new FilletChamferKnotHolderEntity(this, iPlus); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + knot_shape, knot_mode, knot_color); + knotholder->add(e); } - SatellitePairArrayParamKnotHolderEntity *e = - new SatellitePairArrayParamKnotHolderEntity(this, i); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); - knotholder->add(e); + } + if( mirror == true){ + addKnotHolderEntities(knotholder, desktop, item, false); } } -void SatellitePairArrayParam::addKnotHolderEntitieMirrored(KnotHolder *knotholder, +void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item, int i) + SPItem *item) { - using namespace Geom; - SatelliteType type = _vector[i].second.getSatelliteType(); - const gchar *tip; - if (type == C){ - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IC) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IF) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - SatellitePairArrayParamKnotHolderEntity *e = - new SatellitePairArrayParamKnotHolderEntity(this, i + _vector.size()); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); - knotholder->add(e); + addKnotHolderEntities(knotholder, desktop, item, true); } - -SatellitePairArrayParamKnotHolderEntity::SatellitePairArrayParamKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index) +FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index) : _pparam(p), _index(index) { @@ -216,7 +253,7 @@ SatellitePairArrayParamKnotHolderEntity::SatellitePairArrayParamKnotHolderEntity -void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, +void FilletChamferKnotHolderEntity::knot_set(Point const &p, Point const &/*origin*/, guint state) { @@ -244,10 +281,11 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, mirrorTime = timeStart; } double size = satellite.second.toSize(mirrorTime, *d2_in); - double lenght = Geom::length(*d2_in, Geom::EPSILON) - size; - double time = satellite.second.toTime(lenght,pwd2[satellite.first]); - s = pwd2[satellite.first].valueAt(time); - satellite.second.setPosition(s,pwd2[satellite.first]); + double amount = Geom::length(*d2_in, Geom::EPSILON) - size; + if(satellite.second.getIsTime()){ + amount = satellite.second.toTime(amount,pwd2[satellite.first]); + } + satellite.second.setAmount(amount); } } else { satellite.second.setPosition(s,pwd2[satellite.first]); @@ -260,7 +298,7 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, } Geom::Point -SatellitePairArrayParamKnotHolderEntity::knot_get() const +FilletChamferKnotHolderEntity::knot_get() const { Geom::Point tmpPoint; int index = _index; @@ -303,15 +341,19 @@ SatellitePairArrayParamKnotHolderEntity::knot_get() const } -void SatellitePairArrayParamKnotHolderEntity::knot_click(guint state) +void FilletChamferKnotHolderEntity::knot_click(guint state) { + if( _pparam->last_pointwise == NULL){ + return; + } + int index = _index; if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { - _pparam->_vector.at(index).second.setAmmount(0.0); + _pparam->_vector.at(index).second.setAmount(0.0); _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); }else{ @@ -356,9 +398,9 @@ void SatellitePairArrayParamKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - double ammount = _pparam->_vector.at(index).second.getAmmount(); + double amount = _pparam->_vector.at(index).second.getAmount(); if(!_pparam->use_distance && !_pparam->_vector.at(index).second.getIsTime()){ - ammount = _pparam->last_pointwise->len_to_rad(ammount, _pparam->_vector.at(index)); + amount = _pparam->last_pointwise->len_to_rad(amount, _pparam->_vector.at(index)); } boost::optional > d2_in = _pparam->last_pointwise->getCurveIn(_pparam->_vector.at(index)); bool aprox = false; @@ -367,22 +409,29 @@ void SatellitePairArrayParamKnotHolderEntity::knot_click(guint state) aprox = ((*d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; } Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( - this->desktop, ammount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index).second); + this->desktop, amount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index).second); } } -void SatellitePairArrayParamKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) +void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) { + if( _pparam->last_pointwise == NULL){ + return; + } int index = _index; if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } - double ammount = satellite.getAmmount(); + double amount = satellite.getAmount(); + double maxAmount = amount; if(!_pparam->use_distance && !satellite.getIsTime()){ - ammount = _pparam->last_pointwise->rad_to_len(ammount, _pparam->_vector.at(index)); + amount = _pparam->last_pointwise->rad_to_len(amount, _pparam->_vector.at(index)); + if(maxAmount > 0 && amount == 0){ + amount = _pparam->_vector.at(index).second.getAmount(); + } } - satellite.setAmmount(ammount); + satellite.setAmount(amount); _pparam->_vector.at(index).second = satellite; this->parent_holder->knot_ungrabbed_handler(this->knot, 0); _pparam->param_set_and_write_new_value(_pparam->_vector); diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index 21fb0fbd8..79a015c6d 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -20,6 +20,7 @@ #include #include "live_effects/parameter/array.h" +#include "live_effects/effect-enum.h" #include "knot-holder-entity.h" #include <2geom/pointwise.h> @@ -27,7 +28,7 @@ namespace Inkscape { namespace LivePathEffect { -class SatellitePairArrayParamKnotHolderEntity; +class FilletChamferKnotHolderEntity; class SatellitePairArrayParam : public ArrayParam > { public: @@ -46,7 +47,7 @@ public: guint32 color); virtual void set_helper_size(int hs); virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - virtual void addKnotHolderEntitieMirrored(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, int i); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror); virtual void addCanvasIndicators(SPLPEItem const *lpeitem,std::vector &hp_vec); virtual bool providesKnotHolderEntities() const { return true; @@ -54,9 +55,11 @@ public: void set_document_unit(Glib::ustring const * value_document_unit); void set_use_distance(bool use_knot_distance ); void set_unit(const gchar *abbr); + void set_effect_type(EffectType et); virtual void updateCanvasIndicators(); + virtual void updateCanvasIndicators(bool mirror); void set_pointwise(Geom::Pointwise *pointwise); - friend class SatellitePairArrayParamKnotHolderEntity; + friend class FilletChamferKnotHolderEntity; private: SatellitePairArrayParam(const SatellitePairArrayParam &); @@ -70,14 +73,15 @@ private: bool use_distance; const gchar *unit; Glib::ustring const * documentUnit; + EffectType _effectType; Geom::Pointwise *last_pointwise; }; -class SatellitePairArrayParamKnotHolderEntity : public KnotHolderEntity { +class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: - SatellitePairArrayParamKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index); - virtual ~SatellitePairArrayParamKnotHolderEntity() {} + FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index); + virtual ~FilletChamferKnotHolderEntity() {} virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); virtual Geom::Point knot_get() const; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index fe0deba57..8a6cbadad 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 63215d17c..6051b49d3 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( -- cgit v1.2.3 From 580ee6538b069ca74d4159d6b6b8ad6a33bcab4e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 Mar 2015 15:14:26 +0100 Subject: minor changes to helper paths (bzr r13645.1.37) --- src/live_effects/lpe-fillet-chamfer.cpp | 19 +++++++++---------- src/live_effects/lpe-fillet-chamfer.h | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d979171be..ca53bec63 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -57,7 +57,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), - helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), + helper(_("Show helper lines"), _("Show helper lines"), "helper", &wr, this, false), pointwise() { registerParameter(&satellitepairarrayparam_values); @@ -65,13 +65,13 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : registerParameter(&method); registerParameter(&radius); registerParameter(&chamfer_steps); - registerParameter(&helper_size); registerParameter(&flexible); registerParameter(&use_knot_distance); registerParameter(&mirror_knots); registerParameter(&ignore_radius_0); registerParameter(&only_selected); registerParameter(&hide_knots); + registerParameter(&helper); radius.param_set_range(0., infinity()); radius.param_set_increments(1, 1); @@ -79,9 +79,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : chamfer_steps.param_set_range(1, 999); chamfer_steps.param_set_increments(1, 1); chamfer_steps.param_set_digits(0); - helper_size.param_set_range(0, 999); - helper_size.param_set_increments(5, 5); - helper_size.param_set_digits(0); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -193,9 +190,6 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entryWidg = dynamic_cast(childList[1]); entryWidg->set_width_chars(3); } - } else if (param->param_key == "helper_size") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); } else if (param->param_key == "only_selected") { Gtk::manage(widg); } @@ -374,10 +368,15 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //mandatory call satellitepairarrayparam_values.set_pointwise(pointwise); //optional call - if(hide_knots){ + if(hide_knots || !helper){ satellitepairarrayparam_values.set_helper_size(0); } else { - satellitepairarrayparam_values.set_helper_size(helper_size); + double radiusHelperNodes = 6.0; + if(current_zoom != 0){ + radiusHelperNodes *= 1/current_zoom; + radiusHelperNodes = Inkscape::Util::Quantity::convert(radiusHelperNodes, "px", *defaultUnit); + } + satellitepairarrayparam_values.set_helper_size(radiusHelperNodes); } bool changed = false; bool refresh = false; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 3d22216d4..d099d0475 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -62,7 +62,7 @@ private: BoolParam use_knot_distance; BoolParam hide_knots; BoolParam ignore_radius_0; - ScalarParam helper_size; + BoolParam helper; Geom::Pointwise *pointwise; -- cgit v1.2.3 From 4c1951cc43deafcc0131ba6a0878b4f371651f68 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 Mar 2015 16:30:33 +0100 Subject: merged anf fixed from trunk (bzr r13645.1.39) --- src/live_effects/lpe-fillet-chamfer.cpp | 84 +++-------------------- src/live_effects/lpe-fillet-chamfer.h | 2 +- src/live_effects/parameter/satellitepairarray.cpp | 2 +- src/live_effects/parameter/satellitepairarray.h | 4 +- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 10 +-- 5 files changed, 15 insertions(+), 87 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0140f9be9..36dd599d4 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -57,7 +57,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), - helper(_("Show helper lines"), _("Show helper lines"), "helper", &wr, this, false), + helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), pointwise() { registerParameter(&satellitepairarrayparam_values); @@ -65,13 +65,13 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : registerParameter(&method); registerParameter(&radius); registerParameter(&chamfer_steps); + registerParameter(&helper_size); registerParameter(&flexible); registerParameter(&use_knot_distance); registerParameter(&mirror_knots); registerParameter(&ignore_radius_0); registerParameter(&only_selected); registerParameter(&hide_knots); - registerParameter(&helper); radius.param_set_range(0., infinity()); radius.param_set_increments(1, 1); @@ -79,6 +79,9 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : chamfer_steps.param_set_range(1, 999); chamfer_steps.param_set_increments(1, 1); chamfer_steps.param_set_digits(0); + helper_size.param_set_range(0, 999); + helper_size.param_set_increments(5, 5); + helper_size.param_set_digits(0); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -190,6 +193,9 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entryWidg = dynamic_cast(childList[1]); entryWidg->set_width_chars(3); } + } else if (param->param_key == "helper_size") { + Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); + widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); } else if (param->param_key == "only_selected") { Gtk::manage(widg); } @@ -231,60 +237,6 @@ Gtk::Widget *LPEFilletChamfer::newWidget() return vbox; } -void LPEFilletChamfer::toggleHide() -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - for (std::vector::const_iterator point_it = filletChamferData.begin(); - point_it != filletChamferData.end(); ++point_it) { - if (hide_knots) { - result.push_back(Point((*point_it)[X], std::abs((*point_it)[Y]) * -1)); - } else { - result.push_back(Point((*point_it)[X], std::abs((*point_it)[Y]))); - } - } - fillet_chamfer_values.param_set_and_write_new_value(result); - refreshKnots(); -} - -void LPEFilletChamfer::toggleFlexFixed() -{ - std::vector filletChamferData = fillet_chamfer_values.data(); - std::vector result; - unsigned int i = 0; - for (std::vector::const_iterator point_it = filletChamferData.begin(); - point_it != filletChamferData.end(); ++point_it) { - if (flexible) { - result.push_back(Point(fillet_chamfer_values.to_time(i, (*point_it)[X]), - (*point_it)[Y])); - } else { - result.push_back(Point(fillet_chamfer_values.to_len(i, (*point_it)[X]), - (*point_it)[Y])); - } - i++; - } - if (flexible) { - radius.param_set_range(0., 100); - radius.param_set_value(0); - } else { - radius.param_set_range(0., infinity()); - radius.param_set_value(0); - } - fillet_chamfer_values.param_set_and_write_new_value(result); -} - -void LPEFilletChamfer::updateFillet() -{ - double power = 0; - if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), defaultUnit) * -1; - } else { - power = radius; - } - Piecewise > const &pwd2 = fillet_chamfer_values.get_pwd2(); - doUpdateFillet(path_from_piecewise(pwd2, tolerance), power); -} ->>>>>>> MERGE-SOURCE void LPEFilletChamfer::fillet() { @@ -422,26 +374,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //mandatory call satellitepairarrayparam_values.set_pointwise(pointwise); //optional call - if(hide_knots || !helper){ + if(hide_knots){ satellitepairarrayparam_values.set_helper_size(0); } else { - double radiusHelperNodes = 12.0; - if(current_zoom != 0){ - if(current_zoom < 0.5){ - radiusHelperNodes *= current_zoom + 0.4; - } else if(current_zoom > 1) { - radiusHelperNodes *= 1/current_zoom; - } - Geom::Affine i2doc = i2anc_affine(SP_ITEM(lpeItem), SP_OBJECT(SP_ITEM(lpeItem)->document->getRoot())); - double expand = (i2doc.expansionX() + i2doc.expansionY())/2; - if(expand != 0){ - radiusHelperNodes /= expand; - } - radiusHelperNodes = Inkscape::Util::Quantity::convert(radiusHelperNodes, "px", defaultUnit); - } else { - radiusHelperNodes = 0; - } - satellitepairarrayparam_values.set_helper_size(radiusHelperNodes); + satellitepairarrayparam_values.set_helper_size(helper_size); } bool changed = false; bool refresh = false; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index d099d0475..3d22216d4 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -62,7 +62,7 @@ private: BoolParam use_knot_distance; BoolParam hide_knots; BoolParam ignore_radius_0; - BoolParam helper; + ScalarParam helper_size; Geom::Pointwise *pointwise; diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 9c2c1f93b..0fc27153f 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -54,7 +54,7 @@ void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) last_pointwise = pointwise; } -void SatellitePairArrayParam::set_document_unit(Glib::ustring const * value_document_unit) +void SatellitePairArrayParam::set_document_unit(Glib::ustring value_document_unit) { documentUnit = value_document_unit; } diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index 79a015c6d..d20339ccb 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -52,7 +52,7 @@ public: virtual bool providesKnotHolderEntities() const { return true; } - void set_document_unit(Glib::ustring const * value_document_unit); + void set_document_unit(Glib::ustring value_document_unit); void set_use_distance(bool use_knot_distance ); void set_unit(const gchar *abbr); void set_effect_type(EffectType et); @@ -72,7 +72,7 @@ private: int helper_size; bool use_distance; const gchar *unit; - Glib::ustring const * documentUnit; + Glib::ustring documentUnit; EffectType _effectType; Geom::Pointwise *last_pointwise; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index d0f52775a..c6959b718 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; } -- cgit v1.2.3 From 14b24b5d5cc3a8c72d496bea35e16e8ca47ae458 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 14 Mar 2015 22:06:08 +0100 Subject: commit for refactoring (bzr r13645.1.42) --- src/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 +- src/live_effects/parameter/satellitepairarray.cpp | 46 +++++-- src/live_effects/parameter/satellitepairarray.h | 1 + 6 files changed, 209 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 3b182916a..96a7e8644 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 b6bd4c4fd..54f272a13 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 36dd599d4..b94e3c429 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -58,7 +58,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise() + pointwise(NULL) { registerParameter(&satellitepairarrayparam_values); registerParameter(&unit); @@ -400,9 +400,8 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) changed = true; refresh = true; } - bool hide = !hide_knots; - if(it->second.getHidden() != hide){ - it->second.setHidden(hide); + if(it->second.getHidden() != hide_knots){ + it->second.setHidden(hide_knots); changed = true; refresh = true; } @@ -419,6 +418,17 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } } +void +LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) +{ + if (!path_in.empty() && pointwise) { + std::cout << pointwise->getSatellites().size() << "sizefirst\n"; + pointwise->recalculate_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); + std::cout << pointwise->getSatellites().size() << "sizesecond\n"; + satellitepairarrayparam_values.set_pointwise(pointwise); + satellitepairarrayparam_values.param_set_and_write_new_value(pointwise->getSatellites()); + } +} std::vector LPEFilletChamfer::doEffect_path(std::vector const &path_in) @@ -634,15 +644,6 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) return pathvector_out; } -void -LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) -{ - if (!path_in.empty()) { - //satellitepairarrayparam_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); - } -} - - }; //namespace LivePathEffect }; /* namespace Inkscape */ diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 3d22216d4..1bedbefa4 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -39,7 +39,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector const &path_in); virtual Gtk::Widget* newWidget(); - /*double len_to_rad(double A, std::pair sat);*/ + /*double len_to_rad(double A, std::pair sat);*/ void updateSatelliteType(Geom::SatelliteType satellitetype); void updateChamferSteps(); void updateAmount(); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 0fc27153f..45f522693 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -52,6 +52,7 @@ void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) { last_pointwise = pointwise; + std::cout << pointwise->getSatellites().size() << "setted\n"; } void SatellitePairArrayParam::set_document_unit(Glib::ustring value_document_unit) @@ -82,7 +83,7 @@ void SatellitePairArrayParam::set_helper_size(int hs) void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) { - if( last_pointwise == NULL){ + if(!last_pointwise){ return; } Geom::Piecewise > pwd2 = last_pointwise->getPwd2(); @@ -90,7 +91,7 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) hp.clear(); } for (unsigned int i = 0; i < _vector.size(); ++i) { - if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ + if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ continue; } if((!_vector[i].second.getHasMirror() && mirror == true) || _vector[i].second.getAmount() == 0){ @@ -188,13 +189,24 @@ void SatellitePairArrayParam::addCanvasIndicators( hp_vec.push_back(hp); } +void SatellitePairArrayParam::recalculate_knots() +{ + if(last_pointwise){ + _vector = last_pointwise->getSatellites(); + write_to_SVG(); + } +} + void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror) { + std::cout << _vector.size() << "recalculated\n"; + recalculate_knots(); + std::cout << _vector.size() << "recalculated\n"; for (unsigned int i = 0; i < _vector.size(); ++i) { - if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ + if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ continue; } if(!_vector[i].second.getHasMirror() && mirror == true){ @@ -262,10 +274,18 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } - if( _pparam->last_pointwise == NULL){ + if (!valid_index(index)) { + return; + } + + if( !_pparam->last_pointwise ){ return; } + std::pair satellite = _pparam->_vector.at(index); + if(!satellite.second.getActive() || satellite.second.getHidden()){ + return; + } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); if(_pparam->_vector.size() <= _index){ @@ -305,12 +325,21 @@ FilletChamferKnotHolderEntity::knot_get() const if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } + if (!valid_index(index)) { + return Point(infinity(), infinity()); + } std::pair satellite = _pparam->_vector.at(index); - if( _pparam->last_pointwise == NULL){ - return Geom::Point(0,0); + if(!_pparam->last_pointwise){ + return Point(infinity(), infinity()); + } + if(!satellite.second.getActive() || satellite.second.getHidden()){ + return Point(infinity(), infinity()); } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); + std::cout << pointwise->getSatellites().size() << "knotGet\n"; + std::cout << satellite.first << "sindex\n"; + std::cout << _index << "index\n"; if( _index >= _pparam->_vector.size()){ tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); boost::optional > d2_in = pointwise->getCurveIn(satellite); @@ -340,10 +369,9 @@ FilletChamferKnotHolderEntity::knot_get() const return canvas_point; } - void FilletChamferKnotHolderEntity::knot_click(guint state) { - if( _pparam->last_pointwise == NULL){ + if( !_pparam->last_pointwise){ return; } @@ -416,7 +444,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) { - if( _pparam->last_pointwise == NULL){ + if( !_pparam->last_pointwise){ return; } int index = _index; diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index d20339ccb..9b22a386b 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -56,6 +56,7 @@ public: void set_use_distance(bool use_knot_distance ); void set_unit(const gchar *abbr); void set_effect_type(EffectType et); + void recalculate_knots(); virtual void updateCanvasIndicators(); virtual void updateCanvasIndicators(bool mirror); void set_pointwise(Geom::Pointwise *pointwise); -- cgit v1.2.3 From aeffc3f474c1ce460b2c9f8340de283d5853a164 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 19 Mar 2015 19:26:22 +0100 Subject: fixing a boring bug in path manipulator (bzr r13645.1.43) --- src/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 +- src/live_effects/parameter/satellitepairarray.cpp | 59 ++- src/ui/tool/path-manipulator.cpp | 38 +- 9 files changed, 425 insertions(+), 363 deletions(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 96a7e8644..584e78523 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 54f272a13..eb3400877 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 3420db7f6..509c0e074 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 d14a98a7f..43863d71f 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 b94e3c429..0a5d3a224 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -23,6 +23,7 @@ #include <2geom/satellite.h> #include <2geom/satellite-enum.h> #include <2geom/svg-elliptical-arc.h> +#include <2geom/sbasis-to-bezier.h> #include "helper/geom-nodetype.h" #include "helper/geom-curves.h" #include "helper/geom.h" @@ -120,14 +121,13 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) int counter = 0; unsigned int steps = 0; while (curve_it1 != curve_endit) { - bool isStart = false; - if(counter == 0){ - isStart = true; - } - bool isClosing = false; - if(path_it->closed() && curve_it1 == curve_end){ - isClosing = true; + if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ + g_warning("LPE Fillet not handle degenerate curves."); + SPLPEItem * item = const_cast(lpeItem); + item->removeCurrentPathEffect(false); + return; } + bool isEndOpen = false; bool active = true; bool hidden = false; if (counter==0) { @@ -135,7 +135,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0, steps); + Satellite satellite(F, flexible, isEndOpen, active, mirror_knots, hidden, 0.0, 0.0, steps); satellites.push_back(std::make_pair(counterTotal, satellite)); ++curve_it1; counter++; @@ -143,15 +143,15 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } if (!path_it->closed()){ bool active = false; - bool isClosing = false; - bool isStart = false; + bool isEndOpen = true; bool hidden = true; - Satellite satellite(F, flexible, isClosing, isStart, active, mirror_knots, hidden, 0.0, 0.0, steps); - satellites.push_back(std::make_pair(counterTotal, satellite)); + Satellite satellite(F, flexible, isEndOpen, active, mirror_knots, hidden, 0.0, 0.0, steps); + satellites.push_back(std::make_pair(counterTotal-1, satellite)); } } - pointwise = new Pointwise( pwd2_in,satellites); - satellitepairarrayparam_values.param_set_and_write_new_value(satellites); + pointwise = new Pointwise( pwd2_in); + pointwise->setSatellites(satellites); + satellitepairarrayparam_values.set_pointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeItem); @@ -278,13 +278,14 @@ void LPEFilletChamfer::updateAmount() std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(pointwise->findClosingSatellites(it->first).size() == 0 && it->second.getIsStart()){ + if(!pointwise->getIsClosed(it->first) && pointwise->getFirst(it->first) == it->first){ it->second.setAmount(0); continue; } if(ignore_radius_0 && it->second.getAmount() == 0){ continue; } + if(only_selected){ Geom::Point satPoint = pwd2.valueAt(it->first); if(isNodePointSelected(satPoint)){ @@ -301,9 +302,12 @@ void LPEFilletChamfer::updateAmount() it->second.setAmount(power); } } + if(it->second.getIsEndOpen()){ + it->second.setAmount(0); + } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.param_set_and_write_new_value(satellites); + satellitepairarrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() @@ -324,7 +328,7 @@ void LPEFilletChamfer::updateChamferSteps() } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.param_set_and_write_new_value(satellites); + satellitepairarrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) @@ -345,11 +349,12 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.param_set_and_write_new_value(satellites); + satellitepairarrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { + std::cout << "dobeforestart\n"; SPLPEItem * splpeitem = const_cast(lpeItem); SPShape * shape = dynamic_cast(splpeitem); if (shape) { @@ -368,9 +373,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector > satellites = satellitepairarrayparam_values.data(); - pointwise = new Pointwise(pwd2_in,satellites); - + std::vector > sats; + sats = satellitepairarrayparam_values.data(); + pointwise = new Pointwise(pwd2_in); + pointwise->setSatellites(sats); //mandatory call satellitepairarrayparam_values.set_pointwise(pointwise); //optional call @@ -381,7 +387,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } bool changed = false; bool refresh = false; - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = sats.begin(); it != sats.end(); ++it) { if(it->second.getIsTime() != flexible){ it->second.setIsTime(flexible); double amount = it->second.getAmount(); @@ -407,8 +413,8 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } } if(changed){ - pointwise->setSatellites(satellites); - satellitepairarrayparam_values.param_set_and_write_new_value(satellites); + pointwise->setSatellites(sats); + satellitepairarrayparam_values.set_pointwise(pointwise); } if(refresh){ refreshKnots(); @@ -416,23 +422,23 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } + std::cout << "dobeforeend\n"; } void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { - std::cout << pointwise->getSatellites().size() << "sizefirst\n"; - pointwise->recalculate_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); - std::cout << pointwise->getSatellites().size() << "sizesecond\n"; + pointwise->recalculate_for_new_pwd2(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in))); + pointwise->set_extremes(false,true,0.0,0.0); satellitepairarrayparam_values.set_pointwise(pointwise); - satellitepairarrayparam_values.param_set_and_write_new_value(pointwise->getSatellites()); } } std::vector LPEFilletChamfer::doEffect_path(std::vector const &path_in) { + std::cout << "doEffect_pathstart\n"; const double gapHelper = 0.00001; std::vector pathvector_out; unsigned int counter = 0; @@ -447,6 +453,13 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); Geom::Path::const_iterator curve_endit = path_it->end_default(); + if(path_it->size() == 1){ + counter++; + path_out.start((*curve_it1).pointAt(0)); + path_out.append(*curve_it1); + pathvector_out.push_back(path_out); + continue; + } if (path_it->closed()) { const Geom::Curve &closingline = path_it->back_closed(); // the closing line segment is always of type @@ -470,22 +483,44 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) std::vector satVector; Satellite satellite; Curve *curve_it2Fixed = path_it->begin()->duplicate(); - if(!path_it->closed() || curve_it2 != curve_endit){ - curve_it2Fixed = (*curve_it2).duplicate(); - satVector = pointwise->findSatellites(counter+1,1); - if(satVector.size()>0){ - satellite = satVector[0]; + if(!path_it->closed()){ + if(curve_it2 != curve_endit){ + curve_it2Fixed = (*curve_it2).duplicate(); + satVector = pointwise->findSatellites(counter+1,1); + if(satVector.size()>0){ + satellite = satVector[0]; + } + } else { + if(time0 != 1){ + Curve *lastCurve = curve_it1->portion(time0, 1); + lastCurve->setInitial(path_out.finalPoint()); + path_out.append(*lastCurve); + } + ++curve_it1; + counter++; + counterCurves++; + continue; } } else { - satVector = pointwise->findSatellites(first,1); - if(satVector.size()>0){ - satellite = satVector[0]; + if(curve_it2 != curve_endit){ + curve_it2Fixed = (*curve_it2).duplicate(); + satVector = pointwise->findSatellites(counter+1,1); + if(satVector.size()>0){ + satellite = satVector[0]; + } + } else { + satVector = pointwise->findSatellites(first,1); + if(satVector.size()>0){ + satellite = satVector[0]; + } } } if(first == counter){ satVector = pointwise->findSatellites(first,1); - if(satVector.size()>0){ + if(satVector.size()>0 && satVector[0].getActive()){ time0 = satVector[0].getTime(path_it->begin()->duplicate()->toSBasis()); + } else { + time0 = 0; } } @@ -495,8 +530,9 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); if(!satellite.getActive()){ time1 = 1; - time0 = 0; + time2 = 0; } + if(time1 <= time0){ time1 = time0; } @@ -641,6 +677,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } pathvector_out.push_back(path_out); } + std::cout << "doEffect_pathendt\n"; return pathvector_out; } diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index e8a1b9532..d8b2388da 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -54,19 +54,18 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ return 0; } gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray[9] && !strarray[10]){ + if(strarray[8] && !strarray[9]){ sat->setSatelliteType(strarray[0]); sat->setIsTime(strncmp(strarray[1],"1",1) == 0); - sat->setIsClosing(strncmp(strarray[2],"1",1) == 0); - sat->setIsStart(strncmp(strarray[3],"1",1) == 0); - sat->setActive(strncmp(strarray[4],"1",1) == 0); - sat->setHasMirror(strncmp(strarray[5],"1",1) == 0); - sat->setHidden(strncmp(strarray[6],"1",1) == 0); + sat->setIsEndOpen(strncmp(strarray[2],"1",1) == 0); + sat->setActive(strncmp(strarray[3],"1",1) == 0); + sat->setHasMirror(strncmp(strarray[4],"1",1) == 0); + sat->setHidden(strncmp(strarray[5],"1",1) == 0); double amount,angle; float stepsTmp; - sp_svg_number_read_d(strarray[7], &amount); - sp_svg_number_read_d(strarray[8], &angle); - sp_svg_number_read_f(strarray[9], &stepsTmp); + sp_svg_number_read_d(strarray[6], &amount); + sp_svg_number_read_d(strarray[7], &angle); + sp_svg_number_read_f(strarray[8], &stepsTmp); unsigned int steps = (unsigned int)stepsTmp; sat->setAmount(amount); sat->setAngle(angle); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index a6e797d4e..5443cc3c4 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -119,9 +119,7 @@ protected: str << "*"; str << nVector.second.getIsTime(); str << "*"; - str << nVector.second.getIsClosing(); - str << "*"; - str << nVector.second.getIsStart(); + str << nVector.second.getIsEndOpen(); str << "*"; str << nVector.second.getActive(); str << "*"; @@ -134,6 +132,7 @@ protected: str << nVector.second.getAngle(); str << "*"; str << nVector.second.getSteps(); + std::cout << str.str() << "SATEEELIITE\n"; } StorageType readsvg(const gchar * str); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 45f522693..045ef2060 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -52,7 +52,7 @@ void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) { last_pointwise = pointwise; - std::cout << pointwise->getSatellites().size() << "setted\n"; + param_set_and_write_new_value(last_pointwise->getSatellites()); } void SatellitePairArrayParam::set_document_unit(Glib::ustring value_document_unit) @@ -106,20 +106,19 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i].second.getSize(pwd2[_vector[i].first]); double lenght_out = Geom::length(pwd2[_vector[i].first], Geom::EPSILON); double lenght_in = 0; - boost::optional > curve_in = last_pointwise->getCurveIn(_vector[i]); - if(curve_in){ - lenght_in = Geom::length(*curve_in, Geom::EPSILON); + boost::optional d2_prev_index = last_pointwise->getPrevious(_vector[i].first); + if(d2_prev_index){ + lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); } if(mirror == true){ - if(curve_in){ - d2 = *curve_in; - pos = _vector[i].second.getOpositeTime(size_out,*curve_in); + if(d2_prev_index){ + pos = _vector[i].second.getOpositeTime(size_out,pwd2[*d2_prev_index]); if(lenght_out < size_out){ overflow = true; } } } else { - pos = _vector[i].second.getTime(pwd2[_vector[i].first]); + pos = _vector[i].second.getTime(d2); if(lenght_in < size_out){ overflow = true; } @@ -202,20 +201,18 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item, bool mirror) { - std::cout << _vector.size() << "recalculated\n"; recalculate_knots(); - std::cout << _vector.size() << "recalculated\n"; for (unsigned int i = 0; i < _vector.size(); ++i) { + int iPlus = i; + if( mirror == true){ + iPlus = i + _vector.size(); + } if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ continue; } if(!_vector[i].second.getHasMirror() && mirror == true){ continue; } - int iPlus = i; - if( mirror == true){ - iPlus = i + _vector.size(); - } using namespace Geom; SatelliteType type = _vector[i].second.getSatelliteType(); //IF is for filletChamfer effect... @@ -289,19 +286,20 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); if(_pparam->_vector.size() <= _index){ - boost::optional > d2_in = pointwise->getCurveIn(satellite); - if(d2_in){ - double mirrorTime = Geom::nearest_point(s, *d2_in); + boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); + if(d2_prev_index){ + Geom::D2 d2_in = pwd2[*d2_prev_index]; + double mirrorTime = Geom::nearest_point(s, d2_in); double timeStart = 0; std::vector satVector = pointwise->findPeviousSatellites(satellite.first,1); if(satVector.size()>0){ - timeStart = satVector[0].getTime(*d2_in); + timeStart = satVector[0].getTime(d2_in); } if(timeStart > mirrorTime){ mirrorTime = timeStart; } - double size = satellite.second.toSize(mirrorTime, *d2_in); - double amount = Geom::length(*d2_in, Geom::EPSILON) - size; + double size = satellite.second.toSize(mirrorTime, d2_in); + double amount = Geom::length(d2_in, Geom::EPSILON) - size; if(satellite.second.getIsTime()){ amount = satellite.second.toTime(amount,pwd2[satellite.first]); } @@ -337,15 +335,13 @@ FilletChamferKnotHolderEntity::knot_get() const } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - std::cout << pointwise->getSatellites().size() << "knotGet\n"; - std::cout << satellite.first << "sindex\n"; - std::cout << _index << "index\n"; if( _index >= _pparam->_vector.size()){ tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); - boost::optional > d2_in = pointwise->getCurveIn(satellite); - if(d2_in){ + boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); + if(d2_prev_index){ + Geom::D2 d2_in = pwd2[*d2_prev_index]; double s = satellite.second.getSize(pwd2[satellite.first]); - double t = satellite.second.getOpositeTime(s,*d2_in); + double t = satellite.second.getOpositeTime(s,d2_in); if(t > 1){ t = 1; } @@ -355,12 +351,12 @@ FilletChamferKnotHolderEntity::knot_get() const double timeStart = 0; std::vector satVector = pointwise->findPeviousSatellites(satellite.first,1); if(satVector.size()>0){ - timeStart = satVector[0].getTime(*d2_in); + timeStart = satVector[0].getTime(d2_in); } if(timeStart > t){ t = timeStart; } - tmpPoint = (*d2_in).valueAt(t); + tmpPoint = (d2_in).valueAt(t); } } else { tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); @@ -430,11 +426,12 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) if(!_pparam->use_distance && !_pparam->_vector.at(index).second.getIsTime()){ amount = _pparam->last_pointwise->len_to_rad(amount, _pparam->_vector.at(index)); } - boost::optional > d2_in = _pparam->last_pointwise->getCurveIn(_pparam->_vector.at(index)); bool aprox = false; D2 d2_out = _pparam->last_pointwise->getPwd2()[index]; - if(d2_in){ - aprox = ((*d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; + boost::optional d2_prev_index = _pparam->last_pointwise->getPrevious(_pparam->_vector.at(index).first); + if(d2_prev_index){ + Geom::D2 d2_in = _pparam->last_pointwise->getPwd2()[*d2_prev_index]; + aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; } Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( this->desktop, amount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index).second); diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index c8b986824..dbcde240a 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); + } } } } -- cgit v1.2.3 From f3e7b51b1d2497cda7a66e13f4f50da145ece19c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 20 Mar 2015 00:14:47 +0100 Subject: Added delete nodes/satellites (bzr r13645.1.45) --- src/2geom/pointwise.cpp | 34 ++++++++++++++----------- src/2geom/pointwise.h | 2 +- src/live_effects/lpe-fillet-chamfer.cpp | 7 +---- src/live_effects/parameter/array.h | 2 -- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 3 +-- 5 files changed, 22 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 584e78523..8f7a0b402 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 eb3400877..e313722a1 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 0a5d3a224..38645a943 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -119,7 +119,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Path::const_iterator curve_end = curve_endit; --curve_end; int counter = 0; - unsigned int steps = 0; + unsigned int steps = chamfer_steps; while (curve_it1 != curve_endit) { if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ g_warning("LPE Fillet not handle degenerate curves."); @@ -354,7 +354,6 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { - std::cout << "dobeforestart\n"; SPLPEItem * splpeitem = const_cast(lpeItem); SPShape * shape = dynamic_cast(splpeitem); if (shape) { @@ -422,7 +421,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } - std::cout << "dobeforeend\n"; } void @@ -430,7 +428,6 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { pointwise->recalculate_for_new_pwd2(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in))); - pointwise->set_extremes(false,true,0.0,0.0); satellitepairarrayparam_values.set_pointwise(pointwise); } } @@ -438,7 +435,6 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) std::vector LPEFilletChamfer::doEffect_path(std::vector const &path_in) { - std::cout << "doEffect_pathstart\n"; const double gapHelper = 0.00001; std::vector pathvector_out; unsigned int counter = 0; @@ -677,7 +673,6 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } pathvector_out.push_back(path_out); } - std::cout << "doEffect_pathendt\n"; return pathvector_out; } diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 5443cc3c4..7ff477ffb 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -17,7 +17,6 @@ #include <2geom/satellite.h> #include <2geom/satellite-enum.h> -#include <2geom/pointwise.h> #include "svg/svg.h" #include "svg/stringstream.h" @@ -132,7 +131,6 @@ protected: str << nVector.second.getAngle(); str << "*"; str << nVector.second.getSteps(); - std::cout << str.str() << "SATEEELIITE\n"; } StorageType readsvg(const gchar * str); diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index c6959b718..aa27a1414 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; } -- cgit v1.2.3 From cfe5bd077cc29fd43385792435f687d468aca13f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 21 Mar 2015 10:55:27 +0100 Subject: fix bspline calls and atemp to fic a bug whith map (bzr r13645.1.46) --- src/2geom/pointwise.cpp | 109 ++++++++-------------- src/2geom/pointwise.h | 7 +- src/live_effects/lpe-fillet-chamfer.cpp | 46 +++++---- src/live_effects/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(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 8f7a0b402..f476821ff 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 e313722a1..72ff852d0 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 38645a943..09436676c 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -374,17 +374,13 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pwd2_in = remove_short_cuts(pwd2_in, 0.01); std::vector > sats; sats = satellitepairarrayparam_values.data(); - pointwise = new Pointwise(pwd2_in); - pointwise->setSatellites(sats); - //mandatory call - satellitepairarrayparam_values.set_pointwise(pointwise); + //optional call if(hide_knots){ satellitepairarrayparam_values.set_helper_size(0); } else { satellitepairarrayparam_values.set_helper_size(helper_size); } - bool changed = false; bool refresh = false; for (std::vector >::iterator it = sats.begin(); it != sats.end(); ++it) { if(it->second.getIsTime() != flexible){ @@ -398,23 +394,20 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) double size = it->second.toSize(amount,d2_in); it->second.setAmount(size); } - changed = true; } if(it->second.getHasMirror() != mirror_knots){ it->second.setHasMirror(mirror_knots); - changed = true; refresh = true; } if(it->second.getHidden() != hide_knots){ it->second.setHidden(hide_knots); - changed = true; refresh = true; } } - if(changed){ - pointwise->setSatellites(sats); - satellitepairarrayparam_values.set_pointwise(pointwise); - } + pointwise = new Pointwise(pwd2_in); + pointwise->setSatellites(sats); + //mandatory call + satellitepairarrayparam_values.set_pointwise(pointwise); if(refresh){ refreshKnots(); } @@ -428,6 +421,9 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { pointwise->recalculate_for_new_pwd2(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in))); + std::vector > sats = pointwise->getSatellites(); + pointwise->set_extremes(sats,false,true,0.0,0.0); + pointwise->setSatellites(sats); satellitepairarrayparam_values.set_pointwise(pointwise); } } @@ -476,15 +472,15 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) g_warning("LPE Fillet not handle degenerate curves."); return path_in; } - std::vector satVector; + std::vector satIndexes; Satellite satellite; Curve *curve_it2Fixed = path_it->begin()->duplicate(); if(!path_it->closed()){ if(curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); - satVector = pointwise->findSatellites(counter+1,1); - if(satVector.size()>0){ - satellite = satVector[0]; + satIndexes = pointwise->findSatellites(counter+1,1); + if(satIndexes.size()>0){ + satellite = pointwise->getSatellites()[satIndexes[0]].second; } } else { if(time0 != 1){ @@ -500,21 +496,21 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } else { if(curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); - satVector = pointwise->findSatellites(counter+1,1); - if(satVector.size()>0){ - satellite = satVector[0]; + satIndexes = pointwise->findSatellites(counter+1,1); + if(satIndexes.size()>0){ + satellite = pointwise->getSatellites()[satIndexes[0]].second; } } else { - satVector = pointwise->findSatellites(first,1); - if(satVector.size()>0){ - satellite = satVector[0]; + satIndexes = pointwise->findSatellites(first,1); + if(satIndexes.size()>0){ + satellite = pointwise->getSatellites()[satIndexes[0]].second; } } } if(first == counter){ - satVector = pointwise->findSatellites(first,1); - if(satVector.size()>0 && satVector[0].getActive()){ - time0 = satVector[0].getTime(path_it->begin()->duplicate()->toSBasis()); + satIndexes = pointwise->findSatellites(first,1); + if(satIndexes.size()>0 && pointwise->getSatellites()[satIndexes[0]].second.getActive()){ + time0 = pointwise->getSatellites()[satIndexes[0]].second.getTime(path_it->begin()->duplicate()->toSBasis()); } else { time0 = 0; } diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 045ef2060..47f023c29 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -291,9 +291,9 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, Geom::D2 d2_in = pwd2[*d2_prev_index]; double mirrorTime = Geom::nearest_point(s, d2_in); double timeStart = 0; - std::vector satVector = pointwise->findPeviousSatellites(satellite.first,1); - if(satVector.size()>0){ - timeStart = satVector[0].getTime(d2_in); + std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); + if(satIndexes.size()>0){ + timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); } if(timeStart > mirrorTime){ mirrorTime = timeStart; @@ -349,9 +349,9 @@ FilletChamferKnotHolderEntity::knot_get() const t = 0; } double timeStart = 0; - std::vector satVector = pointwise->findPeviousSatellites(satellite.first,1); - if(satVector.size()>0){ - timeStart = satVector[0].getTime(d2_in); + std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); + if(satIndexes.size()>0){ + timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); } if(timeStart > t){ t = timeStart; diff --git a/src/ui/tool/node.cpp b/src/ui/tool/node.cpp index eeea47e4d..5cfc2a0ca 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 dbcde240a..64eba3921 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 4d2bf4300..4badec569 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); -- cgit v1.2.3 From c1487f9dc277520b8734b7e80387b35c78d979ae Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 21 Mar 2015 22:24:37 +0100 Subject: Fixed bug whith maps (bzr r13645.1.49) --- src/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(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index f476821ff..733bd6496 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 72ff852d0..f9dc2e47a 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 b924d8a23..dba501f42 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -1,48 +1,16 @@ /* * Released under GNU GPL, read the file 'COPYING' for more information */ - -#ifdef HAVE_CONFIG_H -# include -#endif - #include - -#if WITH_GLIBMM_2_32 -# include -#endif - -#include -#include - - -#include "display/curve.h" -#include <2geom/bezier-curve.h> -#include <2geom/point.h> -#include "helper/geom-curves.h" #include "live_effects/lpe-bspline.h" -#include "live_effects/lpeobject.h" -#include "live_effects/parameter/parameter.h" #include "ui/widget/scalar.h" -#include "xml/repr.h" -#include "svg/svg.h" +#include "display/curve.h" +#include "helper/geom-curves.h" #include "sp-path.h" -#include "style.h" -#include "document-private.h" -#include "document.h" -#include "document-undo.h" -#include "verbs.h" -#include "sp-lpe-item.h" -#include "sp-namedview.h" -#include "display/sp-canvas.h" -#include -#include -#include "util/units.h" -// For handling un-continuous paths: -#include "message-stack.h" -#include "inkscape.h" - -using Inkscape::DocumentUndo; +#include "svg/svg.h" +#include "xml/repr.h" +// TODO due to internal breakage in glibmm headers, this must be last: +#include namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/lpe-bspline.h b/src/live_effects/lpe-bspline.h index 642562b24..8017e39ef 100644 --- a/src/live_effects/lpe-bspline.h +++ b/src/live_effects/lpe-bspline.h @@ -6,9 +6,8 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ - #include "live_effects/effect.h" -#include "live_effects/parameter/bool.h" + #include namespace Inkscape { diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 09436676c..93c21469a 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -149,8 +149,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) satellites.push_back(std::make_pair(counterTotal-1, satellite)); } } - pointwise = new Pointwise( pwd2_in); - pointwise->setSatellites(satellites); + pointwise = new Pointwise( pwd2_in,satellites); satellitepairarrayparam_values.set_pointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -373,8 +372,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); std::vector > sats; - sats = satellitepairarrayparam_values.data(); - + if(!pointwise){ + sats = satellitepairarrayparam_values.data(); + } else { + sats = pointwise->getSatellites(); + } //optional call if(hide_knots){ satellitepairarrayparam_values.set_helper_size(0); @@ -382,30 +384,29 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellitepairarrayparam_values.set_helper_size(helper_size); } bool refresh = false; - for (std::vector >::iterator it = sats.begin(); it != sats.end(); ++it) { - if(it->second.getIsTime() != flexible){ - it->second.setIsTime(flexible); - double amount = it->second.getAmount(); - D2 d2_in = pwd2_in[it->first]; - if(it->second.getIsTime()){ - double time = it->second.toTime(amount,d2_in); - it->second.setAmount(time); + for(unsigned i = 0; i < sats.size(); i++){ + if(sats[i].second.getIsTime() != flexible){ + sats[i].second.setIsTime(flexible); + double amount = sats[i].second.getAmount(); + D2 d2_in = pwd2_in[sats[i].first]; + if(sats[i].second.getIsTime()){ + double time = sats[i].second.toTime(amount,d2_in); + sats[i].second.setAmount(time); } else { - double size = it->second.toSize(amount,d2_in); - it->second.setAmount(size); + double size = sats[i].second.toSize(amount,d2_in); + sats[i].second.setAmount(size); } } - if(it->second.getHasMirror() != mirror_knots){ - it->second.setHasMirror(mirror_knots); + if(sats[i].second.getHasMirror() != mirror_knots){ + sats[i].second.setHasMirror(mirror_knots); refresh = true; } - if(it->second.getHidden() != hide_knots){ - it->second.setHidden(hide_knots); + if(sats[i].second.getHidden() != hide_knots){ + sats[i].second.setHidden(hide_knots); refresh = true; } } - pointwise = new Pointwise(pwd2_in); - pointwise->setSatellites(sats); + pointwise = new Pointwise(pwd2_in, sats); //mandatory call satellitepairarrayparam_values.set_pointwise(pointwise); if(refresh){ @@ -421,10 +422,7 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { pointwise->recalculate_for_new_pwd2(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in))); - std::vector > sats = pointwise->getSatellites(); - pointwise->set_extremes(sats,false,true,0.0,0.0); - pointwise->setSatellites(sats); - satellitepairarrayparam_values.set_pointwise(pointwise); + pointwise->set_extremes(false,true,0.0,0.0); } } diff --git a/src/ui/tool/multi-path-manipulator.h b/src/ui/tool/multi-path-manipulator.h index cdbf34e9d..1bbcdd7ec 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 8b735f3e6..00e18dd3f 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 4badec569..6dc1c9d09 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); -- cgit v1.2.3 From 8bd246d8b59749e15de4d5d0d78e9b82fa8a601a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 22 Mar 2015 18:27:17 +0100 Subject: Fixed bug when deleting nodes (bzr r13645.1.51) --- src/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 +- src/live_effects/parameter/satellitepairarray.cpp | 37 +++--- src/live_effects/parameter/satellitepairarray.h | 8 +- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 2 +- 10 files changed, 152 insertions(+), 136 deletions(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 733bd6496..9669c20b8 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 f9dc2e47a..a7cbcfec4 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 509c0e074..d1420b20c 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 43863d71f..42ed9c291 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 93c21469a..6b388b0f6 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -51,7 +51,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : unit(_("Unit:"), _("Unit"), "unit", &wr, this), method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), - chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 3), + chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 1), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "mirror_knots", &wr, this, true), only_selected(_("Change only selected nodes"), _("Change only selected nodes"), "only_selected", &wr, this, false), @@ -97,7 +97,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int counterTotal = 0; - std::vector > satellites; + std::vector > satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; @@ -119,7 +119,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Path::const_iterator curve_end = curve_endit; --curve_end; int counter = 0; - unsigned int steps = chamfer_steps; + size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ g_warning("LPE Fillet not handle degenerate curves."); @@ -274,9 +274,9 @@ void LPEFilletChamfer::updateAmount() } else { power = radius/100; } - std::vector > satellites = pointwise->getSatellites(); + std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(!pointwise->getIsClosed(it->first) && pointwise->getFirst(it->first) == it->first){ it->second.setAmount(0); continue; @@ -311,9 +311,9 @@ void LPEFilletChamfer::updateAmount() void LPEFilletChamfer::updateChamferSteps() { - std::vector > satellites = pointwise->getSatellites(); + std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(ignore_radius_0 && it->second.getAmount() == 0){ continue; } @@ -332,9 +332,9 @@ void LPEFilletChamfer::updateChamferSteps() void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) { - std::vector > satellites = pointwise->getSatellites(); + std::vector > satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { + for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { if(ignore_radius_0 && it->second.getAmount() == 0){ continue; } @@ -371,12 +371,8 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector > sats; - if(!pointwise){ - sats = satellitepairarrayparam_values.data(); - } else { - sats = pointwise->getSatellites(); - } + std::vector > sats = satellitepairarrayparam_values.data(); + //optional call if(hide_knots){ satellitepairarrayparam_values.set_helper_size(0); @@ -384,6 +380,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellitepairarrayparam_values.set_helper_size(helper_size); } bool refresh = false; + bool hide = true; for(unsigned i = 0; i < sats.size(); i++){ if(sats[i].second.getIsTime() != flexible){ sats[i].second.setIsTime(flexible); @@ -401,13 +398,17 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) sats[i].second.setHasMirror(mirror_knots); refresh = true; } - if(sats[i].second.getHidden() != hide_knots){ - sats[i].second.setHidden(hide_knots); - refresh = true; + if(sats[i].second.getHidden() == false){ + hide = false; } + sats[i].second.setHidden(hide_knots); + } + if(hide != hide_knots){ + refresh = true; } pointwise = new Pointwise(pwd2_in, sats); //mandatory call + pointwise->set_extremes(false, false, true); satellitepairarrayparam_values.set_pointwise(pointwise); if(refresh){ refreshKnots(); @@ -421,8 +422,9 @@ void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { - pointwise->recalculate_for_new_pwd2(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in))); - pointwise->set_extremes(false,true,0.0,0.0); + pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); + pointwise->set_extremes(true, false, true, 0.0, 0.0); + satellitepairarrayparam_values.set_pointwise(pointwise); } } @@ -431,7 +433,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) { const double gapHelper = 0.00001; std::vector pathvector_out; - unsigned int counter = 0; + size_t counter = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); for (PathVector::const_iterator path_it = path_in_processed.begin(); @@ -462,15 +464,15 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) curve_endit = path_it->end_open(); } } - unsigned int counterCurves = 0; - unsigned int first = counter; + size_t counterCurves = 0; + size_t first = counter; double time0 = 0; while (curve_it1 != curve_endit) { if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ g_warning("LPE Fillet not handle degenerate curves."); return path_in; } - std::vector satIndexes; + std::vector satIndexes; Satellite satellite; Curve *curve_it2Fixed = path_it->begin()->duplicate(); if(!path_it->closed()){ @@ -602,7 +604,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } } SatelliteType type = satellite.getSatelliteType(); - unsigned int steps = satellite.getSteps(); + size_t steps = satellite.getSteps(); if(steps < 1){ steps = 1; } @@ -615,7 +617,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) path_chamfer.appendNew(handle1, handle2, endArcPoint); } double chamfer_stepsTime = 1.0/steps; - for(unsigned int i = 1; i < steps; i++){ + for(size_t i = 1; i < steps; i++){ Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); path_out.appendNew(chamferStep); } @@ -630,7 +632,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); } double chamfer_stepsTime = 1.0/steps; - for(unsigned int i = 1; i < steps; i++){ + for(size_t i = 1; i < steps; i++){ Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); path_out.appendNew(chamferStep); } diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index d8b2388da..33cb53f4e 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -78,20 +78,20 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ } template <> -std::pair -ArrayParam >::readsvg(const gchar * str) +std::pair +ArrayParam >::readsvg(const gchar * str) { gchar ** strarray = g_strsplit(str, ",", 2); double index; - std::pair result; + std::pair result; unsigned int success = (int)sp_svg_number_read_d(strarray[0], &index); Geom::Satellite sat; success += sp_svg_satellite_read_d(strarray[1], &sat); g_strfreev (strarray); if (success == 2) { - return std::make_pair(index, sat); + return std::make_pair((size_t)index, sat); } - return std::make_pair((int)Geom::infinity(),sat); + return std::make_pair((size_t)0,sat); } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 7ff477ffb..4fb053dbb 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -90,7 +90,7 @@ protected: size_t _default_size; void writesvg(SVGOStringStream &str, std::vector const &vector) const { - for (unsigned int i = 0; i < vector.size(); ++i) { + for (size_t i = 0; i < vector.size(); ++i) { if (i != 0) { // separate items with pipe symbol str << " | "; @@ -111,7 +111,7 @@ protected: str << nVector; } - void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { + void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { str << nVector.first; str << ","; str << nVector.second.getSatelliteTypeGchar(); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 47f023c29..8102edf9b 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -11,6 +11,7 @@ #include "knotholder.h" #include "ui/dialog/lpe-fillet-chamfer-properties.h" #include "live_effects/parameter/satellitepairarray.h" +#include "live_effects/effect.h" #include "sp-lpe-item.h" // TODO due to internal breakage in glibmm headers, // this has to be included last. @@ -27,7 +28,7 @@ SatellitePairArrayParam::SatellitePairArrayParam( const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayParam >(label, tip, key, wr, effect, 0) + : ArrayParam >(label, tip, key, wr, effect, 0) { knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; @@ -90,7 +91,7 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) if( mirror == true){ hp.clear(); } - for (unsigned int i = 0; i < _vector.size(); ++i) { + for (size_t i = 0; i < _vector.size(); ++i) { if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ continue; } @@ -106,7 +107,7 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i].second.getSize(pwd2[_vector[i].first]); double lenght_out = Geom::length(pwd2[_vector[i].first], Geom::EPSILON); double lenght_in = 0; - boost::optional d2_prev_index = last_pointwise->getPrevious(_vector[i].first); + boost::optional d2_prev_index = last_pointwise->getPrevious(_vector[i].first); if(d2_prev_index){ lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); } @@ -191,8 +192,7 @@ void SatellitePairArrayParam::addCanvasIndicators( void SatellitePairArrayParam::recalculate_knots() { if(last_pointwise){ - _vector = last_pointwise->getSatellites(); - write_to_SVG(); + //_vector = last_pointwise->getSatellites(); } } @@ -202,8 +202,8 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, bool mirror) { recalculate_knots(); - for (unsigned int i = 0; i < _vector.size(); ++i) { - int iPlus = i; + for (size_t i = 0; i < _vector.size(); ++i) { + size_t iPlus = i; if( mirror == true){ iPlus = i + _vector.size(); } @@ -254,7 +254,7 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, addKnotHolderEntities(knotholder, desktop, item, true); } -FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index) +FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index) : _pparam(p), _index(index) { @@ -267,7 +267,7 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, guint state) { Geom::Point s = snap_knot_position(p, state); - int index = _index; + size_t index = _index; if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } @@ -286,12 +286,12 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); if(_pparam->_vector.size() <= _index){ - boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); + boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); if(d2_prev_index){ Geom::D2 d2_in = pwd2[*d2_prev_index]; double mirrorTime = Geom::nearest_point(s, d2_in); double timeStart = 0; - std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); + std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); if(satIndexes.size()>0){ timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); } @@ -319,7 +319,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const { Geom::Point tmpPoint; - int index = _index; + size_t index = _index; if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } @@ -335,9 +335,12 @@ FilletChamferKnotHolderEntity::knot_get() const } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); + if(pwd2.size() <= (unsigned)satellite.first){ + return Point(infinity(), infinity()); + } if( _index >= _pparam->_vector.size()){ tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); - boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); + boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); if(d2_prev_index){ Geom::D2 d2_in = pwd2[*d2_prev_index]; double s = satellite.second.getSize(pwd2[satellite.first]); @@ -349,7 +352,7 @@ FilletChamferKnotHolderEntity::knot_get() const t = 0; } double timeStart = 0; - std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); + std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); if(satIndexes.size()>0){ timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); } @@ -371,7 +374,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) return; } - int index = _index; + size_t index = _index; if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } @@ -428,7 +431,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } bool aprox = false; D2 d2_out = _pparam->last_pointwise->getPwd2()[index]; - boost::optional d2_prev_index = _pparam->last_pointwise->getPrevious(_pparam->_vector.at(index).first); + boost::optional d2_prev_index = _pparam->last_pointwise->getPrevious(_pparam->_vector.at(index).first); if(d2_prev_index){ Geom::D2 d2_in = _pparam->last_pointwise->getPwd2()[*d2_prev_index]; aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; @@ -444,7 +447,7 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) if( !_pparam->last_pointwise){ return; } - int index = _index; + size_t index = _index; if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index 9b22a386b..a85e3f83f 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -30,7 +30,7 @@ namespace LivePathEffect { class FilletChamferKnotHolderEntity; -class SatellitePairArrayParam : public ArrayParam > { +class SatellitePairArrayParam : public ArrayParam > { public: SatellitePairArrayParam(const Glib::ustring &label, const Glib::ustring &tip, @@ -81,7 +81,7 @@ private: class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: - FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index); + FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index); virtual ~FilletChamferKnotHolderEntity() {} virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); @@ -89,13 +89,13 @@ public: virtual void knot_click(guint state); void knot_set_offset(Geom::Satellite); /** Checks whether the index falls within the size of the parameter's vector */ - bool valid_index(unsigned int index) const { + bool valid_index(size_t index) const { return (_pparam->_vector.size() > index); }; private: SatellitePairArrayParam *_pparam; - unsigned int _index; + size_t _index; }; } //namespace LivePathEffect diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index aa27a1414..6875799f8 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; } -- cgit v1.2.3 From edc48d93d2b528c20b9adb0f7d074c73c46f03eb Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 27 Mar 2015 00:01:44 +0100 Subject: adding append mode (bzr r13645.1.54) --- src/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(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 9669c20b8..b97f8749f 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 a7cbcfec4..296eb6ca6 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 6b388b0f6..55e1f93aa 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -421,8 +421,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { + std::cout << "1111111111111111111111111111111111111111\n"; if (!path_in.empty() && pointwise) { - pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); + std::cout << "222222222222222222222222222222222222222222222\n"; + pointwise->recalculate_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); pointwise->set_extremes(true, false, true, 0.0, 0.0); satellitepairarrayparam_values.set_pointwise(pointwise); } diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index d2bdd9384..ccf75dcde 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" -- cgit v1.2.3 From 13df14f4cf6b48cf01ac54ba0322f50a143c007e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 28 Mar 2015 13:49:37 +0100 Subject: adding append mode (bzr r13645.1.55) --- src/live_effects/lpe-fillet-chamfer.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 55e1f93aa..2fc2027ab 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -372,7 +372,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); std::vector > sats = satellitepairarrayparam_values.data(); - //optional call if(hide_knots){ satellitepairarrayparam_values.set_helper_size(0); @@ -413,6 +412,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if(refresh){ refreshKnots(); } + if(c->nodes_in_path() != sats.size()){ + pointwise->recalculate_for_new_pwd2(pwd2_in); + pointwise->set_extremes(true, false, true, 0.0, 0.0); + satellitepairarrayparam_values.set_pointwise(pointwise); + } } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -421,9 +425,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { - std::cout << "1111111111111111111111111111111111111111\n"; if (!path_in.empty() && pointwise) { - std::cout << "222222222222222222222222222222222222222222222\n"; pointwise->recalculate_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); pointwise->set_extremes(true, false, true, 0.0, 0.0); satellitepairarrayparam_values.set_pointwise(pointwise); -- cgit v1.2.3 From a1cd9b9c2fdb5b4258a14159a3a4baa2782e7d40 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 12:56:46 +0200 Subject: end append path (bzr r13645.1.57) --- src/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 + src/live_effects/parameter/satellitepairarray.cpp | 23 ++- src/live_effects/parameter/satellitepairarray.h | 1 + 6 files changed, 207 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index b97f8749f..bc82780d7 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 296eb6ca6..df3997492 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 2fc2027ab..0502a4192 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -59,7 +59,8 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise(NULL) + pointwise(NULL), + segCount(0) { registerParameter(&satellitepairarrayparam_values); registerParameter(&unit); @@ -380,43 +381,52 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } bool refresh = false; bool hide = true; - for(unsigned i = 0; i < sats.size(); i++){ - if(sats[i].second.getIsTime() != flexible){ - sats[i].second.setIsTime(flexible); - double amount = sats[i].second.getAmount(); - D2 d2_in = pwd2_in[sats[i].first]; - if(sats[i].second.getIsTime()){ - double time = sats[i].second.toTime(amount,d2_in); - sats[i].second.setAmount(time); + for (std::vector >::iterator it = sats.begin(); it != sats.end();) + { + if(it->second.getIsTime() != flexible){ + it->second.setIsTime(flexible); + double amount = it->second.getAmount(); + D2 d2_in = pwd2_in[it->first]; + if(it->second.getIsTime()){ + double time = it->second.toTime(amount,d2_in); + it->second.setAmount(time); } else { - double size = sats[i].second.toSize(amount,d2_in); - sats[i].second.setAmount(size); + double size = it->second.toSize(amount,d2_in); + it->second.setAmount(size); } } - if(sats[i].second.getHasMirror() != mirror_knots){ - sats[i].second.setHasMirror(mirror_knots); + if(it->second.getHasMirror() != mirror_knots){ + it->second.setHasMirror(mirror_knots); refresh = true; } - if(sats[i].second.getHidden() == false){ + if(it->second.getHidden() == false){ hide = false; } - sats[i].second.setHidden(hide_knots); + it->second.setHidden(hide_knots); + if(it->second.getIsEndOpen()){ + it = sats.erase(it); + } else { + ++it; + } } if(hide != hide_knots){ refresh = true; } - pointwise = new Pointwise(pwd2_in, sats); - //mandatory call - pointwise->set_extremes(false, false, true); + + if(pointwise && c->get_segment_count() != segCount && segCount != 0){ + pointwise->recalculate_for_new_pwd2(pwd2_in); + pointwise->set_extremes(false, true, 0.0, 0.0); + segCount = c->get_segment_count(); + } else { + pointwise = new Pointwise(pwd2_in, sats); + //mandatory call + pointwise->set_extremes(false, true); + segCount = c->get_segment_count(); + } satellitepairarrayparam_values.set_pointwise(pointwise); if(refresh){ refreshKnots(); } - if(c->nodes_in_path() != sats.size()){ - pointwise->recalculate_for_new_pwd2(pwd2_in); - pointwise->set_extremes(true, false, true, 0.0, 0.0); - satellitepairarrayparam_values.set_pointwise(pointwise); - } } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -426,8 +436,8 @@ void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { - pointwise->recalculate_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); - pointwise->set_extremes(true, false, true, 0.0, 0.0); + pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); + pointwise->set_extremes(false, true, 0.0, 0.0); satellitepairarrayparam_values.set_pointwise(pointwise); } } @@ -532,10 +542,6 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if(time1 <= time0){ time1 = time0; } - std::cout << counter << ":::::::::::::::::::::::::::::\n"; - std::cout << time0 << "time0\n"; - std::cout << time1 << "time1\n"; - std::cout << time2 << "time2\n"; std::vector times; times.push_back(time0); times.push_back(time1); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 1bedbefa4..89d91265a 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -65,6 +65,7 @@ private: ScalarParam helper_size; Geom::Pointwise *pointwise; + double segCount; LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 8102edf9b..3876dc8df 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -13,6 +13,7 @@ #include "live_effects/parameter/satellitepairarray.h" #include "live_effects/effect.h" #include "sp-lpe-item.h" +#include // TODO due to internal breakage in glibmm headers, // this has to be included last. #include @@ -113,7 +114,8 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) } if(mirror == true){ if(d2_prev_index){ - pos = _vector[i].second.getOpositeTime(size_out,pwd2[*d2_prev_index]); + d2 = pwd2[*d2_prev_index]; + pos = _vector[i].second.getOpositeTime(size_out,d2); if(lenght_out < size_out){ overflow = true; } @@ -196,6 +198,24 @@ void SatellitePairArrayParam::recalculate_knots() } } +void +SatellitePairArrayParam::param_transform_multiply(Geom::Affine const &postmul, + bool /*set*/) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + if (prefs->getBool("/options/transform/rectcorners", true)) { + for (size_t i = 0; i < _vector.size(); ++i) { + if(!_vector[i].second.getIsTime() && _vector[i].second.getAmount() > 0){ + _vector[i].second.setAmount(_vector[i].second.getAmount() * ((postmul.expansionX() + postmul.expansionY()) / 2)); + } + } + param_set_and_write_new_value(_vector); + } + + // param_set_and_write_new_value( (*this) * postmul ); +} + void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, @@ -315,6 +335,7 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, } } + Geom::Point FilletChamferKnotHolderEntity::knot_get() const { diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index a85e3f83f..462f1017c 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -52,6 +52,7 @@ public: virtual bool providesKnotHolderEntities() const { return true; } + void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void set_document_unit(Glib::ustring value_document_unit); void set_use_distance(bool use_knot_distance ); void set_unit(const gchar *abbr); -- cgit v1.2.3 From 7acc0ec6f6a0756b73baa2bc815113984f6f3ea6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 13:23:02 +0200 Subject: change pointwise comment (bzr r13645.1.59) --- src/2geom/pointwise.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index df3997492..0eb7c7073 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. -- cgit v1.2.3 From 842a3a6415e837f502671ff098525bba9d8a0362 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 13:50:29 +0200 Subject: Remove active desktop calls from LPE (bzr r13645.1.60) --- src/live_effects/lpe-fillet-chamfer.cpp | 11 +++-------- src/live_effects/parameter/satellitepairarray.cpp | 4 +++- src/live_effects/parameter/satellitepairarray.h | 6 ++++-- 3 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0502a4192..0f767435f 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,9 +16,6 @@ #include "live_effects/lpe-fillet-chamfer.h" -#include "live_effects/lpeobject.h" -#include -#include #include <2geom/pointwise.h> #include <2geom/satellite.h> #include <2geom/satellite-enum.h> @@ -28,7 +25,7 @@ #include "helper/geom-curves.h" #include "helper/geom.h" #include "display/curve.h" -#include "ui/tools-switch.h" +#include "knotholder.h" #include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -260,10 +257,8 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (tools_isactive(desktop, TOOLS_NODES)) { - tools_switch(desktop, TOOLS_SELECT); - tools_switch(desktop, TOOLS_NODES); + if(satellitepairarrayparam_values.knoth){ + satellitepairarrayparam_values.knoth->update_knots(); } } diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 3876dc8df..dd67be6a1 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -29,7 +29,8 @@ SatellitePairArrayParam::SatellitePairArrayParam( const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayParam >(label, tip, key, wr, effect, 0) + : ArrayParam >(label, tip, key, wr, effect, 0), + knoth(NULL) { knot_shape = SP_KNOT_SHAPE_DIAMOND; knot_mode = SP_KNOT_MODE_XOR; @@ -271,6 +272,7 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { + knoth = knotholder; addKnotHolderEntities(knotholder, desktop, item, true); } diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index 462f1017c..fcd3bd736 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -62,7 +62,9 @@ public: virtual void updateCanvasIndicators(bool mirror); void set_pointwise(Geom::Pointwise *pointwise); friend class FilletChamferKnotHolderEntity; - + friend class LPEFilletChamfer; +protected: + KnotHolder *knoth; private: SatellitePairArrayParam(const SatellitePairArrayParam &); SatellitePairArrayParam &operator=(const SatellitePairArrayParam &); @@ -83,7 +85,7 @@ private: class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index); - virtual ~FilletChamferKnotHolderEntity() {} + virtual ~FilletChamferKnotHolderEntity() {_pparam->knoth = NULL;} virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); virtual Geom::Point knot_get() const; -- cgit v1.2.3 From a309dd74bad06a293cae9f70f575024eed0b652a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 16:50:35 +0200 Subject: fixed hide knots and removed unused headers (bzr r13645.1.61) --- src/live_effects/lpe-fillet-chamfer.cpp | 10 +++------- src/live_effects/parameter/satellitepairarray.cpp | 11 ++++++----- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0f767435f..6775fa000 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,17 +16,13 @@ #include "live_effects/lpe-fillet-chamfer.h" -#include <2geom/pointwise.h> #include <2geom/satellite.h> #include <2geom/satellite-enum.h> -#include <2geom/svg-elliptical-arc.h> -#include <2geom/sbasis-to-bezier.h> -#include "helper/geom-nodetype.h" -#include "helper/geom-curves.h" #include "helper/geom.h" #include "display/curve.h" +#include "helper/geom-curves.h" +#include <2geom/svg-elliptical-arc.h> #include "knotholder.h" -#include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -46,7 +42,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), satellitepairarrayparam_values(_("pair_array_param"), _("pair_array_param"), "satellitepairarrayparam_values", &wr, this), unit(_("Unit:"), _("Unit"), "unit", &wr, this), - method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), + method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 1), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index dd67be6a1..0748269f4 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -195,7 +195,7 @@ void SatellitePairArrayParam::addCanvasIndicators( void SatellitePairArrayParam::recalculate_knots() { if(last_pointwise){ - //_vector = last_pointwise->getSatellites(); + _vector = last_pointwise->getSatellites(); } } @@ -222,13 +222,13 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item, bool mirror) { - recalculate_knots(); + //recalculate_knots(); for (size_t i = 0; i < _vector.size(); ++i) { size_t iPlus = i; if( mirror == true){ iPlus = i + _vector.size(); } - if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ + if(!_vector[i].second.getActive()){ continue; } if(!_vector[i].second.getHasMirror() && mirror == true){ @@ -282,8 +282,6 @@ FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatellitePairArrayP { } - - void FilletChamferKnotHolderEntity::knot_set(Point const &p, Point const &/*origin*/, guint state) @@ -353,6 +351,7 @@ FilletChamferKnotHolderEntity::knot_get() const if(!_pparam->last_pointwise){ return Point(infinity(), infinity()); } + std::cout << satellite.second.getHidden() << "hiddden\n"; if(!satellite.second.getActive() || satellite.second.getHidden()){ return Point(infinity(), infinity()); } @@ -361,6 +360,8 @@ FilletChamferKnotHolderEntity::knot_get() const if(pwd2.size() <= (unsigned)satellite.first){ return Point(infinity(), infinity()); } + this->knot->show(); + std::cout << satellite.second.getHidden() << "show\n"; if( _index >= _pparam->_vector.size()){ tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); -- cgit v1.2.3 From cb6f3fcd6fc271c32e1a1afcf946b7ca75a161d7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 31 Mar 2015 16:51:21 +0200 Subject: removed code comments (bzr r13645.1.62) --- src/live_effects/parameter/satellitepairarray.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 0748269f4..461a6b54e 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -351,7 +351,6 @@ FilletChamferKnotHolderEntity::knot_get() const if(!_pparam->last_pointwise){ return Point(infinity(), infinity()); } - std::cout << satellite.second.getHidden() << "hiddden\n"; if(!satellite.second.getActive() || satellite.second.getHidden()){ return Point(infinity(), infinity()); } @@ -361,7 +360,6 @@ FilletChamferKnotHolderEntity::knot_get() const return Point(infinity(), infinity()); } this->knot->show(); - std::cout << satellite.second.getHidden() << "show\n"; if( _index >= _pparam->_vector.size()){ tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); -- cgit v1.2.3 From dff3aa428ff050c2cce501f646977ddad921feca Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 04:13:16 +0200 Subject: Move 2Geom work to a intermediate positon -helper- Removed dependency to helper/geom.h Now use a simple vector, not a vector of pairs of size_t and Satellite Getters and setters on Satellite removed Update store parameter to a more friendly string, like powerstroke Todo: Documentation and Fix coding style. (bzr r13645.1.63) --- src/2geom/Makefile_insert | 4 - src/2geom/pointwise.cpp | 519 --------------------- src/2geom/pointwise.h | 108 ----- src/2geom/satellite-enum.h | 51 --- src/2geom/satellite.cpp | 156 ------- src/2geom/satellite.h | 188 -------- src/helper/Makefile_insert | 7 + src/helper/geom-pathinfo.cpp | 178 ++++++++ src/helper/geom-pathinfo.h | 81 ++++ src/helper/geom-pointwise.cpp | 268 +++++++++++ src/helper/geom-pointwise.h | 96 ++++ src/helper/geom-satellite-enum.h | 51 +++ src/helper/geom-satellite.cpp | 237 ++++++++++ src/helper/geom-satellite.h | 87 ++++ src/live_effects/CMakeLists.txt | 4 +- src/live_effects/lpe-fillet-chamfer.cpp | 173 ++++--- src/live_effects/lpe-fillet-chamfer.h | 9 +- src/live_effects/parameter/Makefile_insert | 4 +- src/live_effects/parameter/array.cpp | 77 ++-- src/live_effects/parameter/array.h | 38 +- src/live_effects/parameter/satellitearray.cpp | 524 ++++++++++++++++++++++ src/live_effects/parameter/satellitearray.h | 108 +++++ src/live_effects/parameter/satellitepairarray.cpp | 507 --------------------- src/live_effects/parameter/satellitepairarray.h | 108 ----- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 24 +- src/ui/dialog/lpe-fillet-chamfer-properties.h | 2 +- 26 files changed, 1793 insertions(+), 1816 deletions(-) delete mode 100644 src/2geom/pointwise.cpp delete mode 100644 src/2geom/pointwise.h delete mode 100644 src/2geom/satellite-enum.h delete mode 100644 src/2geom/satellite.cpp delete mode 100644 src/2geom/satellite.h create mode 100644 src/helper/geom-pathinfo.cpp create mode 100644 src/helper/geom-pathinfo.h create mode 100644 src/helper/geom-pointwise.cpp create mode 100644 src/helper/geom-pointwise.h create mode 100644 src/helper/geom-satellite-enum.h create mode 100644 src/helper/geom-satellite.cpp create mode 100644 src/helper/geom-satellite.h create mode 100644 src/live_effects/parameter/satellitearray.cpp create mode 100644 src/live_effects/parameter/satellitearray.h delete mode 100644 src/live_effects/parameter/satellitepairarray.cpp delete mode 100644 src/live_effects/parameter/satellitepairarray.h (limited to 'src') diff --git a/src/2geom/Makefile_insert b/src/2geom/Makefile_insert index 8872065fb..e77f413cb 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 bc82780d7..000000000 --- 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/pointwise.h b/src/2geom/pointwise.h deleted file mode 100644 index 0eb7c7073..000000000 --- a/src/2geom/pointwise.h +++ /dev/null @@ -1,108 +0,0 @@ -/** - * \file - * \brief Pointwise - *//* - * 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. - * - */ - -#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/sbasis-to-bezier.h> -#include <2geom/path.h> -#include "helper/geom.h" -#include - -namespace Geom { -/** - * %Pointwise function class. - */ - -class Pointwise -{ - public: - 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); - 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 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; -}; - -} // end namespace Geom - -#endif //SEEN_GEOM_POINTWISE_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-enum.h b/src/2geom/satellite-enum.h deleted file mode 100644 index bcd8d1bb3..000000000 --- a/src/2geom/satellite-enum.h +++ /dev/null @@ -1,51 +0,0 @@ -#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" -/*#include -*/ - -namespace Geom { - -enum SatelliteType { - F=0, //Fillet - IF, //Inverse Fillet - C, //Chamfer - IC, //Inverse Chamfer - 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 - -/* - 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.cpp b/src/2geom/satellite.cpp deleted file mode 100644 index d1420b20c..000000000 --- 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/2geom/satellite.h b/src/2geom/satellite.h deleted file mode 100644 index 42ed9c291..000000000 --- a/src/2geom/satellite.h +++ /dev/null @@ -1,188 +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. - */ - -#ifndef LIB2GEOM_SEEN_SATELLITE_H -#define LIB2GEOM_SEEN_SATELLITE_H - -#include <2geom/satellite-enum.h> -#include <2geom/d2.h> -#include -#include - -namespace Geom { - -class Satellite -{ - public: - - Satellite(); - Satellite(SatelliteType satellitetype, bool isTime, bool isEndOpen, 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; - 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; -}; - -} // 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 : diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index e59fcfb70..1d051734e 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 000000000..c8ba01bd0 --- /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 000000000..1696fd366 --- /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 000000000..4926bcc47 --- /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/helper/geom-pointwise.h b/src/helper/geom-pointwise.h new file mode 100644 index 000000000..8b5c275b9 --- /dev/null +++ b/src/helper/geom-pointwise.h @@ -0,0 +1,96 @@ +/** + * \file + * \brief Pointwise + *//* + * 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. + * + */ + +#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 +#include +#include <2geom/sbasis-to-bezier.h> +#include <2geom/path.h> +#include + +namespace Geom { +/** + * %Pointwise function class. + */ + +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 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); + + private: + Piecewise > _pwd2; + std::vector _satellites; + Pathinfo _pathInfo; +}; + +} // end namespace Geom + +#endif //SEEN_GEOM_POINTWISE_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-satellite-enum.h b/src/helper/geom-satellite-enum.h new file mode 100644 index 000000000..bcd8d1bb3 --- /dev/null +++ b/src/helper/geom-satellite-enum.h @@ -0,0 +1,51 @@ +#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" +/*#include +*/ + +namespace Geom { + +enum SatelliteType { + F=0, //Fillet + IF, //Inverse Fillet + C, //Chamfer + IC, //Inverse Chamfer + 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 + +/* + 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 new file mode 100644 index 000000000..73201445a --- /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/helper/geom-satellite.h b/src/helper/geom-satellite.h new file mode 100644 index 000000000..f367bb7f3 --- /dev/null +++ b/src/helper/geom-satellite.h @@ -0,0 +1,87 @@ +/** + * \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. + */ + +#ifndef LIB2GEOM_SEEN_SATELLITE_H +#define LIB2GEOM_SEEN_SATELLITE_H + +#include +#include <2geom/d2.h> +#include +#include + +namespace Geom { + +class Satellite +{ + public: + + Satellite(); + Satellite(SatelliteType satelliteType, bool isTime, bool active, bool hasMirror, bool hidden, double amount, double angle, size_t steps); + + 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; + 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 + +#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 : diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 3af27a220..7bafb356d 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -62,7 +62,7 @@ set(live_effects_SRC parameter/path-reference.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp - parameter/satellitepairarray.cpp + parameter/satellitearray.cpp parameter/random.cpp parameter/text.cpp paramter/transformedpoint.cpp @@ -138,7 +138,7 @@ set(live_effects_SRC parameter/originalpatharray.h parameter/point.h parameter/powerstrokepointarray.h - parameter/satellitepairarray.h + parameter/satellitearray.h parameter/random.h parameter/text.h parameter/togglebutton.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6775fa000..54b2fb52f 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,13 +16,15 @@ #include "live_effects/lpe-fillet-chamfer.h" -#include <2geom/satellite.h> -#include <2geom/satellite-enum.h> #include "helper/geom.h" #include "display/curve.h" #include "helper/geom-curves.h" +#include "helper/geom-satellite.h" +#include "helper/geom-satellite-enum.h" +#include "helper/geom-pathinfo.h" #include <2geom/svg-elliptical-arc.h> #include "knotholder.h" +#include // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -40,7 +42,7 @@ FMConverter(FilletMethodData, FM_END); LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellitepairarrayparam_values(_("pair_array_param"), _("pair_array_param"), "satellitepairarrayparam_values", &wr, this), + satellitearrayparam_values(_("pair_array_param"), _("pair_array_param"), "satellitearrayparam_values", &wr, this), unit(_("Unit:"), _("Unit"), "unit", &wr, this), method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), @@ -55,7 +57,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : pointwise(NULL), segCount(0) { - registerParameter(&satellitepairarrayparam_values); + registerParameter(&satellitearrayparam_values); registerParameter(&unit); registerParameter(&method); registerParameter(&radius); @@ -91,7 +93,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int counterTotal = 0; - std::vector > satellites; + std::vector satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; @@ -121,7 +123,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) item->removeCurrentPathEffect(false); return; } - bool isEndOpen = false; bool active = true; bool hidden = false; if (counter==0) { @@ -129,22 +130,15 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, isEndOpen, active, mirror_knots, hidden, 0.0, 0.0, steps); - satellites.push_back(std::make_pair(counterTotal, satellite)); + Satellite satellite(F, flexible, active, mirror_knots, hidden, 0.0, 0.0, steps); + satellites.push_back(satellite); ++curve_it1; counter++; counterTotal++; } - if (!path_it->closed()){ - bool active = false; - bool isEndOpen = true; - bool hidden = true; - Satellite satellite(F, flexible, isEndOpen, active, mirror_knots, hidden, 0.0, 0.0, steps); - satellites.push_back(std::make_pair(counterTotal-1, satellite)); - } } pointwise = new Pointwise( pwd2_in,satellites); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast(lpeItem); @@ -253,8 +247,8 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - if(satellitepairarrayparam_values.knoth){ - satellitepairarrayparam_values.knoth->update_knots(); + if(satellitearrayparam_values.knoth){ + satellitearrayparam_values.knoth->update_knots(); } } @@ -266,81 +260,85 @@ void LPEFilletChamfer::updateAmount() } else { power = radius/100; } - std::vector > satellites = pointwise->getSatellites(); + std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(!pointwise->getIsClosed(it->first) && pointwise->getFirst(it->first) == it->first){ - it->second.setAmount(0); + Pathinfo pathInfo(pwd2); + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(!pathInfo.getIsClosed(it - satellites.begin()) && pathInfo.getFirst(it - satellites.begin()) == (unsigned)(it - satellites.begin())){ + it->amount = 0; continue; } - if(ignore_radius_0 && it->second.getAmount() == 0){ + if(ignore_radius_0 && it->amount == 0){ continue; } - + boost::optional prev = pathInfo.getPrevious(it - satellites.begin()); + boost::optional > prevPwd2 = boost::none; + boost::optional prevSat = boost::none; + if(prev){ + prevPwd2 = pwd2[*prev]; + prevSat = satellites[*prev]; + } if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it->first); + Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); if(isNodePointSelected(satPoint)){ if(!use_knot_distance && !flexible){ - it->second.setAmount(pointwise->rad_to_len(power,*it)); + it->amount = it->rad_to_len(power, prevPwd2, pwd2[it - satellites.begin()], prevSat); } else { - it->second.setAmount(power); + it->amount = power; } } } else { if(!use_knot_distance && !flexible){ - it->second.setAmount(pointwise->rad_to_len(power,*it)); + it->amount = it->rad_to_len(power, prevPwd2, pwd2[it - satellites.begin()], prevSat); } else { - it->second.setAmount(power); + it->amount = power; } } - if(it->second.getIsEndOpen()){ - it->second.setAmount(0); - } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() { - std::vector > satellites = pointwise->getSatellites(); + std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->second.getAmount() == 0){ + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(ignore_radius_0 && it->amount == 0){ continue; } if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it->first); + Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); if(isNodePointSelected(satPoint)){ - it->second.setSteps(chamfer_steps); + it->steps = chamfer_steps; } } else { - it->second.setSteps(chamfer_steps); + it->steps = chamfer_steps; } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) { - std::vector > satellites = pointwise->getSatellites(); + std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->second.getAmount() == 0){ + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(ignore_radius_0 && it->amount == 0){ continue; } if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it->first); + Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); if(isNodePointSelected(satPoint)){ - it->second.setSatelliteType(satellitetype); + it->satelliteType = satellitetype; } } else { - it->second.setSatelliteType(satellitetype); + it->satelliteType = satellitetype; } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -354,51 +352,47 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } //fillet chamfer specific calls - satellitepairarrayparam_values.set_document_unit(defaultUnit); - satellitepairarrayparam_values.set_use_distance(use_knot_distance); - satellitepairarrayparam_values.set_unit(unit.get_abbreviation()); + satellitearrayparam_values.set_document_unit(defaultUnit); + satellitearrayparam_values.set_use_distance(use_knot_distance); + satellitearrayparam_values.set_unit(unit.get_abbreviation()); //mandatory call - satellitepairarrayparam_values.set_effect_type(this->effectType()); + satellitearrayparam_values.set_effect_type(this->effectType()); PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector > sats = satellitepairarrayparam_values.data(); + std::vector sats = satellitearrayparam_values.data(); //optional call if(hide_knots){ - satellitepairarrayparam_values.set_helper_size(0); + satellitearrayparam_values.set_helper_size(0); } else { - satellitepairarrayparam_values.set_helper_size(helper_size); + satellitearrayparam_values.set_helper_size(helper_size); } bool refresh = false; bool hide = true; - for (std::vector >::iterator it = sats.begin(); it != sats.end();) + for (std::vector::iterator it = sats.begin(); it != sats.end();) { - if(it->second.getIsTime() != flexible){ - it->second.setIsTime(flexible); - double amount = it->second.getAmount(); - D2 d2_in = pwd2_in[it->first]; - if(it->second.getIsTime()){ - double time = it->second.toTime(amount,d2_in); - it->second.setAmount(time); + if(it->isTime != flexible){ + it->isTime = flexible; + double amount = it->amount; + D2 d2_in = pwd2_in[it - sats.begin()]; + if(it->isTime){ + double time = it->toTime(amount,d2_in); + it->amount = time; } else { - double size = it->second.toSize(amount,d2_in); - it->second.setAmount(size); + double size = it->toSize(amount,d2_in); + it->amount = size; } } - if(it->second.getHasMirror() != mirror_knots){ - it->second.setHasMirror(mirror_knots); + if(it->hasMirror != mirror_knots){ + it->hasMirror = mirror_knots; refresh = true; } - if(it->second.getHidden() == false){ + if(it->hidden == false){ hide = false; } - it->second.setHidden(hide_knots); - if(it->second.getIsEndOpen()){ - it = sats.erase(it); - } else { - ++it; - } + it->hidden = hide_knots; + ++it; } if(hide != hide_knots){ refresh = true; @@ -414,7 +408,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise->set_extremes(false, true); segCount = c->get_segment_count(); } - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); if(refresh){ refreshKnots(); } @@ -429,7 +423,7 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) if (!path_in.empty() && pointwise) { pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); pointwise->set_extremes(false, true, 0.0, 0.0); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } } @@ -472,20 +466,19 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) size_t counterCurves = 0; size_t first = counter; double time0 = 0; + std::vector sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ g_warning("LPE Fillet not handle degenerate curves."); return path_in; } - std::vector satIndexes; Satellite satellite; Curve *curve_it2Fixed = path_it->begin()->duplicate(); if(!path_it->closed()){ if(curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); - satIndexes = pointwise->findSatellites(counter+1,1); - if(satIndexes.size()>0){ - satellite = pointwise->getSatellites()[satIndexes[0]].second; + if(sats.size()> counter+1 ){ + satellite = sats[counter+1]; } } else { if(time0 != 1){ @@ -501,21 +494,19 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } else { if(curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); - satIndexes = pointwise->findSatellites(counter+1,1); - if(satIndexes.size()>0){ - satellite = pointwise->getSatellites()[satIndexes[0]].second; + if(sats.size()> counter+1 ){ + satellite = sats[counter+1]; } + } else { - satIndexes = pointwise->findSatellites(first,1); - if(satIndexes.size()>0){ - satellite = pointwise->getSatellites()[satIndexes[0]].second; + if(sats.size()> first ){ + satellite = sats[first]; } } } if(first == counter){ - satIndexes = pointwise->findSatellites(first,1); - if(satIndexes.size()>0 && pointwise->getSatellites()[satIndexes[0]].second.getActive()){ - time0 = pointwise->getSatellites()[satIndexes[0]].second.getTime(path_it->begin()->duplicate()->toSBasis()); + if(sats.size() > first && sats[first].active){ + time0 = sats[first].getTime(path_it->begin()->duplicate()->toSBasis()); } else { time0 = 0; } @@ -525,7 +516,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double s = satellite.getSize(curve_it2Fixed->toSBasis()); double time1 = satellite.getOpositeTime(s,(*curve_it1).toSBasis()); double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); - if(!satellite.getActive()){ + if(!satellite.active){ time1 = 1; time2 = 0; } @@ -604,8 +595,8 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) path_out.append(*knotCurve1); } } - SatelliteType type = satellite.getSatelliteType(); - size_t steps = satellite.getSteps(); + SatelliteType type = satellite.satelliteType; + size_t steps = satellite.steps; if(steps < 1){ steps = 1; } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 89d91265a..e56200a17 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -14,11 +14,12 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ + #include "live_effects/parameter/enum.h" #include "live_effects/parameter/unit.h" -#include "2geom/pointwise.h" -#include "live_effects/parameter/satellitepairarray.h" +#include "live_effects/parameter/satellitearray.h" #include "live_effects/effect.h" +#include "helper/geom-pointwise.h" namespace Inkscape { namespace LivePathEffect { @@ -39,7 +40,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector const &path_in); virtual Gtk::Widget* newWidget(); - /*double len_to_rad(double A, std::pair sat);*/ + void updateSatelliteType(Geom::SatelliteType satellitetype); void updateChamferSteps(); void updateAmount(); @@ -49,7 +50,7 @@ public: void fillet(); void inverseFillet(); - SatellitePairArrayParam satellitepairarrayparam_values; + SatelliteArrayParam satellitearrayparam_values; private: UnitParam unit; diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index 74b499fa2..9a0ebe235 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -22,8 +22,8 @@ ink_common_sources += \ live_effects/parameter/originalpatharray.h \ live_effects/parameter/powerstrokepointarray.cpp \ live_effects/parameter/powerstrokepointarray.h \ - live_effects/parameter/satellitepairarray.cpp \ - live_effects/parameter/satellitepairarray.h \ + live_effects/parameter/satellitearray.cpp \ + live_effects/parameter/satellitearray.h \ live_effects/parameter/text.cpp \ live_effects/parameter/text.h \ live_effects/parameter/transformedpoint.cpp \ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 33cb53f4e..c8ee63fec 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -5,9 +5,7 @@ */ #include "live_effects/parameter/array.h" - #include "helper-fns.h" - #include <2geom/coord.h> #include <2geom/point.h> @@ -15,6 +13,35 @@ namespace Inkscape { namespace LivePathEffect { +//TODO: move maybe to svg-lenght.cpp +unsigned int +sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ + if (!str) { + return 0; + } + gchar ** strarray = g_strsplit(str, ",", 8); + if(strarray[7] && !strarray[8]){ + sat->setSatelliteType(g_strstrip(strarray[0])); + sat->isTime = strncmp(strarray[1],"1",1) == 0; + sat->active = strncmp(strarray[2],"1",1) == 0; + sat->hasMirror = strncmp(strarray[3],"1",1) == 0; + sat->hidden = strncmp(strarray[4],"1",1) == 0; + double amount,angle; + float stepsTmp; + sp_svg_number_read_d(strarray[5], &amount); + sp_svg_number_read_d(strarray[6], &angle); + sp_svg_number_read_f(strarray[7], &stepsTmp); + unsigned int steps = (unsigned int)stepsTmp; + sat->amount = amount; + sat->angle = angle; + sat->steps = steps; + g_strfreev (strarray); + return 1; + } + g_strfreev (strarray); + return 0; +} + template <> double ArrayParam::readsvg(const gchar * str) @@ -47,51 +74,17 @@ ArrayParam::readsvg(const gchar * str) } return Geom::Point(Geom::infinity(),Geom::infinity()); } -//TODO: move maybe to svg-lenght.cpp -unsigned int -sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ - if (!str) { - return 0; - } - gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray[8] && !strarray[9]){ - sat->setSatelliteType(strarray[0]); - sat->setIsTime(strncmp(strarray[1],"1",1) == 0); - sat->setIsEndOpen(strncmp(strarray[2],"1",1) == 0); - sat->setActive(strncmp(strarray[3],"1",1) == 0); - sat->setHasMirror(strncmp(strarray[4],"1",1) == 0); - sat->setHidden(strncmp(strarray[5],"1",1) == 0); - double amount,angle; - float stepsTmp; - sp_svg_number_read_d(strarray[6], &amount); - sp_svg_number_read_d(strarray[7], &angle); - sp_svg_number_read_f(strarray[8], &stepsTmp); - unsigned int steps = (unsigned int)stepsTmp; - sat->setAmount(amount); - sat->setAngle(angle); - sat->setSteps(steps); - g_strfreev (strarray); - return 1; - } - g_strfreev (strarray); - return 0; -} template <> -std::pair -ArrayParam >::readsvg(const gchar * str) +Geom::Satellite +ArrayParam::readsvg(const gchar * str) { - gchar ** strarray = g_strsplit(str, ",", 2); - double index; - std::pair result; - unsigned int success = (int)sp_svg_number_read_d(strarray[0], &index); Geom::Satellite sat; - success += sp_svg_satellite_read_d(strarray[1], &sat); - g_strfreev (strarray); - if (success == 2) { - return std::make_pair((size_t)index, sat); + if (sp_svg_satellite_read_d(str, &sat)) { + return sat; } - return std::make_pair((size_t)0,sat); + Geom::Satellite satellite(Geom::F, true, false, false, true, 0.0, 0.0, 0); + return satellite; } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 4fb053dbb..25e479304 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -15,8 +15,8 @@ #include "live_effects/parameter/parameter.h" -#include <2geom/satellite.h> -#include <2geom/satellite-enum.h> +#include "helper/geom-satellite.h" +#include "helper/geom-satellite-enum.h" #include "svg/svg.h" #include "svg/stringstream.h" @@ -111,26 +111,22 @@ protected: str << nVector; } - void writesvgData(SVGOStringStream &str, std::pair const &nVector) const { - str << nVector.first; + void writesvgData(SVGOStringStream &str, Geom::Satellite const &nVector) const { + str << nVector.getSatelliteTypeGchar(); str << ","; - str << nVector.second.getSatelliteTypeGchar(); - str << "*"; - str << nVector.second.getIsTime(); - str << "*"; - str << nVector.second.getIsEndOpen(); - str << "*"; - str << nVector.second.getActive(); - str << "*"; - str << nVector.second.getHasMirror(); - str << "*"; - str << nVector.second.getHidden(); - str << "*"; - str << nVector.second.getAmount(); - str << "*"; - str << nVector.second.getAngle(); - str << "*"; - str << nVector.second.getSteps(); + str << nVector.isTime; + str << ","; + str << nVector.active; + str << ","; + str << nVector.hasMirror; + str << ","; + str << nVector.hidden; + str << ","; + str << nVector.amount; + str << ","; + str << nVector.angle; + str << ","; + str << nVector.steps; } StorageType readsvg(const gchar * str); diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp new file mode 100644 index 000000000..24a491b4b --- /dev/null +++ b/src/live_effects/parameter/satellitearray.cpp @@ -0,0 +1,524 @@ +/* + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "knotholder.h" +#include "ui/dialog/lpe-fillet-chamfer-properties.h" +#include "live_effects/parameter/satellitearray.h" +#include "live_effects/effect.h" +#include "sp-lpe-item.h" +#include +#include +// TODO due to internal breakage in glibmm headers, +// this has to be included last. +#include + + +using namespace Geom; + +namespace Inkscape { + +namespace LivePathEffect { + +SatelliteArrayParam::SatelliteArrayParam( + const Glib::ustring &label, const Glib::ustring &tip, + const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, + Effect *effect) + : ArrayParam(label, tip, key, wr, effect, 0), + knoth(NULL) +{ + knot_shape = SP_KNOT_SHAPE_DIAMOND; + knot_mode = SP_KNOT_MODE_XOR; + knot_color = 0x00ff0000; + helper_size = 0; + use_distance = false; + _effectType = FILLET_CHAMFER; + last_pointwise = NULL; +} + +SatelliteArrayParam::~SatelliteArrayParam() {} + +void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, + SPKnotModeType mode, + guint32 color) +{ + knot_shape = shape; + knot_mode = mode; + knot_color = color; +} + +void SatelliteArrayParam::set_pointwise(Geom::Pointwise *pointwise) +{ + last_pointwise = pointwise; + param_set_and_write_new_value(last_pointwise->getSatellites()); +} + +void SatelliteArrayParam::set_document_unit(Glib::ustring value_document_unit) +{ + documentUnit = value_document_unit; +} + +void SatelliteArrayParam::set_use_distance(bool use_knot_distance ) +{ + use_distance = use_knot_distance; +} + +void SatelliteArrayParam::set_unit(const gchar *abbr) +{ + unit = abbr; +} + +void SatelliteArrayParam::set_effect_type(EffectType et) +{ + _effectType = et; +} + +void SatelliteArrayParam::set_helper_size(int hs) +{ + helper_size = hs; + updateCanvasIndicators(); +} + +void SatelliteArrayParam::updateCanvasIndicators(bool mirror) +{ + if(!last_pointwise){ + return; + } + Geom::Piecewise > pwd2 = last_pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); + if( mirror == true){ + hp.clear(); + } + for (size_t i = 0; i < _vector.size(); ++i) { + if(!_vector[i].active || _vector[i].hidden){ + continue; + } + if((!_vector[i].hasMirror && mirror == true) || _vector[i].amount == 0){ + continue; + } + double pos = 0; + if(pwd2.size() <= i){ + break; + } + Geom::D2 d2 = pwd2[i]; + bool overflow = false; + double size_out = _vector[i].getSize(pwd2[i]); + double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); + double lenght_in = 0; + boost::optional d2_prev_index = pathInfo.getPrevious(i); + if(d2_prev_index){ + lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); + } + if(mirror == true){ + if(d2_prev_index){ + d2 = pwd2[*d2_prev_index]; + pos = _vector[i].getOpositeTime(size_out,d2); + if(lenght_out < size_out){ + overflow = true; + } + } + } else { + pos = _vector[i].getTime(d2); + if(lenght_in < size_out){ + overflow = true; + } + } + if (pos <= 0 || pos >= 1) { + continue; + } + Geom::Point ptA = d2.valueAt(pos); + Geom::Point derivA = unit_vector(derivative(d2).valueAt(pos)); + Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); + derivA = derivA * rot; + Geom::Point C = ptA - derivA * helper_size; + Geom::Point D = ptA + derivA * helper_size; + Geom::Ray ray1(C, D); + char const * svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + Geom::Affine aff = Geom::Affine(); + aff *= Geom::Scale(helper_size); + if(mirror == true){ + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); + } else { + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); + } + pathv *= aff; + pathv += d2.valueAt(pos); + hp.push_back(pathv[0]); + hp.push_back(pathv[1]); + if(overflow){ + double diameter = helper_size; + if(helper_size == 0){ + diameter = 15; + char const * svgd; + svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + pathv *= Geom::Scale (diameter); + pathv += ptA-Geom::Point(diameter * 0.35,diameter * 0.35); + hp.push_back(pathv[0]); + } else { + char const * svgd; + svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A 1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 0 -1.32 z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + aff = Geom::Affine(); + aff *= Geom::Scale(helper_size/2.0); + if(mirror == true){ + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); + } else { + aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); + } + pathv *= aff; + pathv += d2.valueAt(pos); + hp.push_back(pathv[0]); + } + } + } + if( mirror == true){ + updateCanvasIndicators(false); + } +} +void SatelliteArrayParam::updateCanvasIndicators() +{ + updateCanvasIndicators(true); +} + +void SatelliteArrayParam::addCanvasIndicators( + SPLPEItem const */*lpeitem*/, std::vector &hp_vec) +{ + hp_vec.push_back(hp); +} + +void SatelliteArrayParam::recalculate_knots() +{ + if(last_pointwise){ + _vector = last_pointwise->getSatellites(); + } +} + +void +SatelliteArrayParam::param_transform_multiply(Geom::Affine const &postmul, + bool /*set*/) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + if (prefs->getBool("/options/transform/rectcorners", true)) { + for (size_t i = 0; i < _vector.size(); ++i) { + if(!_vector[i].isTime && _vector[i].amount > 0){ + _vector[i].amount = _vector[i].amount * ((postmul.expansionX() + postmul.expansionY()) / 2); + } + } + param_set_and_write_new_value(_vector); + } + + // param_set_and_write_new_value( (*this) * postmul ); +} + +void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item, + bool mirror) +{ + //recalculate_knots(); + for (size_t i = 0; i < _vector.size(); ++i) { + size_t iPlus = i; + if( mirror == true){ + iPlus = i + _vector.size(); + } + if(!_vector[i].active){ + continue; + } + if(!_vector[i].hasMirror && mirror == true){ + continue; + } + using namespace Geom; + SatelliteType type = _vector[i].satelliteType; + //IF is for filletChamfer effect... + if(_effectType == FILLET_CHAMFER){ + const gchar *tip; + if (type == C){ + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IC) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IF) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } + FilletChamferKnotHolderEntity *e = + new FilletChamferKnotHolderEntity(this, iPlus); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + knot_shape, knot_mode, knot_color); + knotholder->add(e); + } + } + if( mirror == true){ + addKnotHolderEntities(knotholder, desktop, item, false); + } +} + +void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item) +{ + knoth = knotholder; + addKnotHolderEntities(knotholder, desktop, item, true); +} + +FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index) + : _pparam(p), + _index(index) +{ +} + +void FilletChamferKnotHolderEntity::knot_set(Point const &p, + Point const &/*origin*/, + guint state) +{ + Geom::Point s = snap_knot_position(p, state); + size_t index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + if (!valid_index(index)) { + return; + } + + if( !_pparam->last_pointwise ){ + return; + } + + Geom::Satellite satellite = _pparam->_vector.at(index); + if(!satellite.active || satellite.hidden){ + return; + } + Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); + if(_pparam->_vector.size() <= _index){ + boost::optional d2_prev_index = pathInfo.getPrevious(index); + if(d2_prev_index){ + Geom::D2 d2_in = pwd2[*d2_prev_index]; + double mirrorTime = Geom::nearest_point(s, d2_in); + double timeStart = 0; + std::vector sats = pointwise->getSatellites(); + timeStart = sats[*d2_prev_index].getTime(d2_in); + if(timeStart > mirrorTime){ + mirrorTime = timeStart; + } + double size = satellite.toSize(mirrorTime, d2_in); + double amount = Geom::length(d2_in, Geom::EPSILON) - size; + if(satellite.isTime){ + amount = satellite.toTime(amount,pwd2[index]); + } + satellite.amount = amount; + } + } else { + satellite.setPosition(s,pwd2[index]); + } + _pparam->_vector.at(index) = satellite; + SPLPEItem * splpeitem = dynamic_cast(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); + } +} + + +Geom::Point +FilletChamferKnotHolderEntity::knot_get() const +{ + Geom::Point tmpPoint; + size_t index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + if (!valid_index(index)) { + return Point(infinity(), infinity()); + } + Geom::Satellite satellite = _pparam->_vector.at(index); + if(!_pparam->last_pointwise){ + return Point(infinity(), infinity()); + } + if(!satellite.active || satellite.hidden){ + return Point(infinity(), infinity()); + } + Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); + if(pwd2.size() <= index){ + return Point(infinity(), infinity()); + } + this->knot->show(); + if( _index >= _pparam->_vector.size()){ + tmpPoint = satellite.getPosition(pwd2[index]); + boost::optional d2_prev_index = pathInfo.getPrevious(index); + if(d2_prev_index){ + Geom::D2 d2_in = pwd2[*d2_prev_index]; + double s = satellite.getSize(pwd2[index]); + double t = satellite.getOpositeTime(s,d2_in); + if(t > 1){ + t = 1; + } + if(t < 0){ + t = 0; + } + double timeStart = 0; + timeStart = pointwise->getSatellites()[*d2_prev_index].getTime(d2_in); + if(timeStart > t){ + t = timeStart; + } + tmpPoint = (d2_in).valueAt(t); + } + } else { + tmpPoint = satellite.getPosition(pwd2[index]); + } + Geom::Point const canvas_point = tmpPoint; + return canvas_point; +} + +void FilletChamferKnotHolderEntity::knot_click(guint state) +{ + if( !_pparam->last_pointwise){ + return; + } + + size_t index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + if (state & GDK_CONTROL_MASK) { + if (state & GDK_MOD1_MASK) { + _pparam->_vector.at(index).amount = 0.0; + _pparam->param_set_and_write_new_value(_pparam->_vector); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + }else{ + using namespace Geom; + SatelliteType type = _pparam->_vector.at(index).satelliteType; + switch(type){ + case F: + type = IF; + break; + case IF: + type = C; + break; + case C: + type = IC; + break; + default: + type = F; + break; + } + _pparam->_vector.at(index).satelliteType = type; + _pparam->param_set_and_write_new_value(_pparam->_vector); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + const gchar *tip; + if (type == C){ + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IC) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == IF) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } + this->knot->tip = g_strdup(tip); + this->knot->show(); + } + } else if (state & GDK_SHIFT_MASK) { + Piecewise > pwd2 = _pparam->last_pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); + double amount = _pparam->_vector.at(index).amount; + if(!_pparam->use_distance && !_pparam->_vector.at(index).isTime){ + boost::optional prev = pathInfo.getPrevious(index); + boost::optional > prevPwd2 = boost::none; + boost::optional prevSat = boost::none; + if(prev){ + prevPwd2 = pwd2[*prev]; + prevSat = _pparam->_vector.at(*prev); + } + amount = _pparam->_vector.at(index).len_to_rad(amount, prevPwd2, pwd2[index], prevSat); + } + bool aprox = false; + D2 d2_out = _pparam->last_pointwise->getPwd2()[index]; + boost::optional d2_prev_index = pathInfo.getPrevious(index); + if(d2_prev_index){ + Geom::D2 d2_in = _pparam->last_pointwise->getPwd2()[*d2_prev_index]; + aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; + } + Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( + this->desktop, amount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index)); + + } +} + +void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) +{ + if( !_pparam->last_pointwise){ + return; + } + size_t index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + double amount = satellite.amount; + double maxAmount = amount; + if(!_pparam->use_distance && !satellite.isTime){ + Piecewise > pwd2 = _pparam->last_pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); + boost::optional prev = pathInfo.getPrevious(index); + boost::optional > prevPwd2 = boost::none; + boost::optional prevSat = boost::none; + if(prev){ + prevPwd2 = pwd2[*prev]; + prevSat = _pparam->_vector.at(*prev); + } + amount = _pparam->_vector.at(index).rad_to_len(amount, prevPwd2, pwd2[index], prevSat); + if(maxAmount > 0 && amount == 0){ + amount = _pparam->_vector.at(index).amount; + } + } + satellite.amount = amount; + _pparam->_vector.at(index) = satellite; + this->parent_holder->knot_ungrabbed_handler(this->knot, 0); + _pparam->param_set_and_write_new_value(_pparam->_vector); + SPLPEItem * splpeitem = dynamic_cast(item); + if(splpeitem){ + sp_lpe_item_update_patheffect(splpeitem, false, false); + } +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/satellitearray.h b/src/live_effects/parameter/satellitearray.h new file mode 100644 index 000000000..ee0cfbad3 --- /dev/null +++ b/src/live_effects/parameter/satellitearray.h @@ -0,0 +1,108 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H +#define INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H + +/* + * Inkscape::LivePathEffectParameters + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * To Nathan Hurst for his review and help on refactor + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * + * + * This parameter act as bridge from pointwise class to serialize it as a LPE + * parameter + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/array.h" +#include "live_effects/effect-enum.h" +#include "helper/geom-pointwise.h" +#include "knot-holder-entity.h" +#include + +namespace Inkscape { + +namespace LivePathEffect { + +class FilletChamferKnotHolderEntity; + +class SatelliteArrayParam : public ArrayParam { +public: + SatelliteArrayParam(const Glib::ustring &label, + const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, + Effect *effect); + virtual ~SatelliteArrayParam(); + + virtual Gtk::Widget * param_newWidget() { + return NULL; + } + + void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, + guint32 color); + virtual void set_helper_size(int hs); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror); + virtual void addCanvasIndicators(SPLPEItem const *lpeitem,std::vector &hp_vec); + virtual bool providesKnotHolderEntities() const { + return true; + } + void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); + void set_document_unit(Glib::ustring value_document_unit); + void set_use_distance(bool use_knot_distance ); + void set_unit(const gchar *abbr); + void set_effect_type(EffectType et); + void recalculate_knots(); + virtual void updateCanvasIndicators(); + virtual void updateCanvasIndicators(bool mirror); + void set_pointwise(Geom::Pointwise *pointwise); + friend class FilletChamferKnotHolderEntity; + friend class LPEFilletChamfer; +protected: + KnotHolder *knoth; +private: + SatelliteArrayParam(const SatelliteArrayParam &); + SatelliteArrayParam &operator=(const SatelliteArrayParam &); + + SPKnotShapeType knot_shape; + SPKnotModeType knot_mode; + guint32 knot_color; + Geom::PathVector hp; + int helper_size; + bool use_distance; + const gchar *unit; + Glib::ustring documentUnit; + EffectType _effectType; + Geom::Pointwise *last_pointwise; + +}; + +class FilletChamferKnotHolderEntity : public KnotHolderEntity { +public: + FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index); + virtual ~FilletChamferKnotHolderEntity() {_pparam->knoth = NULL;} + + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual Geom::Point knot_get() const; + virtual void knot_click(guint state); + void knot_set_offset(Geom::Satellite); + /** Checks whether the index falls within the size of the parameter's vector */ + bool valid_index(size_t index) const { + return (_pparam->_vector.size() > index); + }; + +private: + SatelliteArrayParam *_pparam; + size_t _index; +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp deleted file mode 100644 index 461a6b54e..000000000 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ /dev/null @@ -1,507 +0,0 @@ -/* - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "knotholder.h" -#include "ui/dialog/lpe-fillet-chamfer-properties.h" -#include "live_effects/parameter/satellitepairarray.h" -#include "live_effects/effect.h" -#include "sp-lpe-item.h" -#include -// TODO due to internal breakage in glibmm headers, -// this has to be included last. -#include - - -using namespace Geom; - -namespace Inkscape { - -namespace LivePathEffect { - -SatellitePairArrayParam::SatellitePairArrayParam( - const Glib::ustring &label, const Glib::ustring &tip, - const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, - Effect *effect) - : ArrayParam >(label, tip, key, wr, effect, 0), - knoth(NULL) -{ - knot_shape = SP_KNOT_SHAPE_DIAMOND; - knot_mode = SP_KNOT_MODE_XOR; - knot_color = 0x00ff0000; - helper_size = 0; - use_distance = false; - _effectType = FILLET_CHAMFER; - last_pointwise = NULL; -} - -SatellitePairArrayParam::~SatellitePairArrayParam() {} - -void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, - SPKnotModeType mode, - guint32 color) -{ - knot_shape = shape; - knot_mode = mode; - knot_color = color; -} - -void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) -{ - last_pointwise = pointwise; - param_set_and_write_new_value(last_pointwise->getSatellites()); -} - -void SatellitePairArrayParam::set_document_unit(Glib::ustring value_document_unit) -{ - documentUnit = value_document_unit; -} - -void SatellitePairArrayParam::set_use_distance(bool use_knot_distance ) -{ - use_distance = use_knot_distance; -} - -void SatellitePairArrayParam::set_unit(const gchar *abbr) -{ - unit = abbr; -} - -void SatellitePairArrayParam::set_effect_type(EffectType et) -{ - _effectType = et; -} - -void SatellitePairArrayParam::set_helper_size(int hs) -{ - helper_size = hs; - updateCanvasIndicators(); -} - -void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) -{ - if(!last_pointwise){ - return; - } - Geom::Piecewise > pwd2 = last_pointwise->getPwd2(); - if( mirror == true){ - hp.clear(); - } - for (size_t i = 0; i < _vector.size(); ++i) { - if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ - continue; - } - if((!_vector[i].second.getHasMirror() && mirror == true) || _vector[i].second.getAmount() == 0){ - continue; - } - double pos = 0; - if(pwd2.size() <= (unsigned)_vector[i].first){ - break; - } - Geom::D2 d2 = pwd2[_vector[i].first]; - bool overflow = false; - double size_out = _vector[i].second.getSize(pwd2[_vector[i].first]); - double lenght_out = Geom::length(pwd2[_vector[i].first], Geom::EPSILON); - double lenght_in = 0; - boost::optional d2_prev_index = last_pointwise->getPrevious(_vector[i].first); - if(d2_prev_index){ - lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); - } - if(mirror == true){ - if(d2_prev_index){ - d2 = pwd2[*d2_prev_index]; - pos = _vector[i].second.getOpositeTime(size_out,d2); - if(lenght_out < size_out){ - overflow = true; - } - } - } else { - pos = _vector[i].second.getTime(d2); - if(lenght_in < size_out){ - overflow = true; - } - } - if (pos <= 0 || pos >= 1) { - continue; - } - Geom::Point ptA = d2.valueAt(pos); - Geom::Point derivA = unit_vector(derivative(d2).valueAt(pos)); - Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); - derivA = derivA * rot; - Geom::Point C = ptA - derivA * helper_size; - Geom::Point D = ptA + derivA * helper_size; - Geom::Ray ray1(C, D); - char const * svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - Geom::Affine aff = Geom::Affine(); - aff *= Geom::Scale(helper_size); - if(mirror == true){ - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); - } else { - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); - } - pathv *= aff; - pathv += d2.valueAt(pos); - hp.push_back(pathv[0]); - hp.push_back(pathv[1]); - if(overflow){ - double diameter = helper_size; - if(helper_size == 0){ - diameter = 15; - char const * svgd; - svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - pathv *= Geom::Scale (diameter); - pathv += ptA-Geom::Point(diameter * 0.35,diameter * 0.35); - hp.push_back(pathv[0]); - } else { - char const * svgd; - svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A 1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 0 -1.32 z"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - aff = Geom::Affine(); - aff *= Geom::Scale(helper_size/2.0); - if(mirror == true){ - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); - } else { - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); - } - pathv *= aff; - pathv += d2.valueAt(pos); - hp.push_back(pathv[0]); - } - } - } - if( mirror == true){ - updateCanvasIndicators(false); - } -} -void SatellitePairArrayParam::updateCanvasIndicators() -{ - updateCanvasIndicators(true); -} - -void SatellitePairArrayParam::addCanvasIndicators( - SPLPEItem const */*lpeitem*/, std::vector &hp_vec) -{ - hp_vec.push_back(hp); -} - -void SatellitePairArrayParam::recalculate_knots() -{ - if(last_pointwise){ - _vector = last_pointwise->getSatellites(); - } -} - -void -SatellitePairArrayParam::param_transform_multiply(Geom::Affine const &postmul, - bool /*set*/) -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - if (prefs->getBool("/options/transform/rectcorners", true)) { - for (size_t i = 0; i < _vector.size(); ++i) { - if(!_vector[i].second.getIsTime() && _vector[i].second.getAmount() > 0){ - _vector[i].second.setAmount(_vector[i].second.getAmount() * ((postmul.expansionX() + postmul.expansionY()) / 2)); - } - } - param_set_and_write_new_value(_vector); - } - - // param_set_and_write_new_value( (*this) * postmul ); -} - -void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item, - bool mirror) -{ - //recalculate_knots(); - for (size_t i = 0; i < _vector.size(); ++i) { - size_t iPlus = i; - if( mirror == true){ - iPlus = i + _vector.size(); - } - if(!_vector[i].second.getActive()){ - continue; - } - if(!_vector[i].second.getHasMirror() && mirror == true){ - continue; - } - using namespace Geom; - SatelliteType type = _vector[i].second.getSatelliteType(); - //IF is for filletChamfer effect... - if(_effectType == FILLET_CHAMFER){ - const gchar *tip; - if (type == C){ - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IC) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IF) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - FilletChamferKnotHolderEntity *e = - new FilletChamferKnotHolderEntity(this, iPlus); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); - knotholder->add(e); - } - } - if( mirror == true){ - addKnotHolderEntities(knotholder, desktop, item, false); - } -} - -void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item) -{ - knoth = knotholder; - addKnotHolderEntities(knotholder, desktop, item, true); -} - -FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index) - : _pparam(p), - _index(index) -{ -} - -void FilletChamferKnotHolderEntity::knot_set(Point const &p, - Point const &/*origin*/, - guint state) -{ - Geom::Point s = snap_knot_position(p, state); - size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); - } - if (!valid_index(index)) { - return; - } - - if( !_pparam->last_pointwise ){ - return; - } - - std::pair satellite = _pparam->_vector.at(index); - if(!satellite.second.getActive() || satellite.second.getHidden()){ - return; - } - Geom::Pointwise* pointwise = _pparam->last_pointwise; - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - if(_pparam->_vector.size() <= _index){ - boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); - if(d2_prev_index){ - Geom::D2 d2_in = pwd2[*d2_prev_index]; - double mirrorTime = Geom::nearest_point(s, d2_in); - double timeStart = 0; - std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); - if(satIndexes.size()>0){ - timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); - } - if(timeStart > mirrorTime){ - mirrorTime = timeStart; - } - double size = satellite.second.toSize(mirrorTime, d2_in); - double amount = Geom::length(d2_in, Geom::EPSILON) - size; - if(satellite.second.getIsTime()){ - amount = satellite.second.toTime(amount,pwd2[satellite.first]); - } - satellite.second.setAmount(amount); - } - } else { - satellite.second.setPosition(s,pwd2[satellite.first]); - } - _pparam->_vector.at(index) = satellite; - SPLPEItem * splpeitem = dynamic_cast(item); - if(splpeitem){ - sp_lpe_item_update_patheffect(splpeitem, false, false); - } -} - - -Geom::Point -FilletChamferKnotHolderEntity::knot_get() const -{ - Geom::Point tmpPoint; - size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); - } - if (!valid_index(index)) { - return Point(infinity(), infinity()); - } - std::pair satellite = _pparam->_vector.at(index); - if(!_pparam->last_pointwise){ - return Point(infinity(), infinity()); - } - if(!satellite.second.getActive() || satellite.second.getHidden()){ - return Point(infinity(), infinity()); - } - Geom::Pointwise* pointwise = _pparam->last_pointwise; - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - if(pwd2.size() <= (unsigned)satellite.first){ - return Point(infinity(), infinity()); - } - this->knot->show(); - if( _index >= _pparam->_vector.size()){ - tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); - boost::optional d2_prev_index = pointwise->getPrevious(satellite.first); - if(d2_prev_index){ - Geom::D2 d2_in = pwd2[*d2_prev_index]; - double s = satellite.second.getSize(pwd2[satellite.first]); - double t = satellite.second.getOpositeTime(s,d2_in); - if(t > 1){ - t = 1; - } - if(t < 0){ - t = 0; - } - double timeStart = 0; - std::vector satIndexes = pointwise->findPeviousSatellites(satellite.first,1); - if(satIndexes.size()>0){ - timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); - } - if(timeStart > t){ - t = timeStart; - } - tmpPoint = (d2_in).valueAt(t); - } - } else { - tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); - } - Geom::Point const canvas_point = tmpPoint; - return canvas_point; -} - -void FilletChamferKnotHolderEntity::knot_click(guint state) -{ - if( !_pparam->last_pointwise){ - return; - } - - size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); - } - if (state & GDK_CONTROL_MASK) { - if (state & GDK_MOD1_MASK) { - _pparam->_vector.at(index).second.setAmount(0.0); - _pparam->param_set_and_write_new_value(_pparam->_vector); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - }else{ - using namespace Geom; - SatelliteType type = _pparam->_vector.at(index).second.getSatelliteType(); - switch(type){ - case F: - type = IF; - break; - case IF: - type = C; - break; - case C: - type = IC; - break; - default: - type = F; - break; - } - _pparam->_vector.at(index).second.setSatelliteType(type); - _pparam->param_set_and_write_new_value(_pparam->_vector); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - const gchar *tip; - if (type == C){ - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IC) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == IF) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - this->knot->tip = g_strdup(tip); - this->knot->show(); - } - } else if (state & GDK_SHIFT_MASK) { - double amount = _pparam->_vector.at(index).second.getAmount(); - if(!_pparam->use_distance && !_pparam->_vector.at(index).second.getIsTime()){ - amount = _pparam->last_pointwise->len_to_rad(amount, _pparam->_vector.at(index)); - } - bool aprox = false; - D2 d2_out = _pparam->last_pointwise->getPwd2()[index]; - boost::optional d2_prev_index = _pparam->last_pointwise->getPrevious(_pparam->_vector.at(index).first); - if(d2_prev_index){ - Geom::D2 d2_in = _pparam->last_pointwise->getPwd2()[*d2_prev_index]; - aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; - } - Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( - this->desktop, amount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index).second); - - } -} - -void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) -{ - if( !_pparam->last_pointwise){ - return; - } - size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); - } - double amount = satellite.getAmount(); - double maxAmount = amount; - if(!_pparam->use_distance && !satellite.getIsTime()){ - amount = _pparam->last_pointwise->rad_to_len(amount, _pparam->_vector.at(index)); - if(maxAmount > 0 && amount == 0){ - amount = _pparam->_vector.at(index).second.getAmount(); - } - } - satellite.setAmount(amount); - _pparam->_vector.at(index).second = satellite; - this->parent_holder->knot_ungrabbed_handler(this->knot, 0); - _pparam->param_set_and_write_new_value(_pparam->_vector); - SPLPEItem * splpeitem = dynamic_cast(item); - if(splpeitem){ - sp_lpe_item_update_patheffect(splpeitem, false, false); - } -} - -} /* namespace LivePathEffect */ - -} /* namespace Inkscape */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h deleted file mode 100644 index fcd3bd736..000000000 --- a/src/live_effects/parameter/satellitepairarray.h +++ /dev/null @@ -1,108 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H -#define INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H - -/* - * Inkscape::LivePathEffectParameters - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * To Nathan Hurst for his review and help on refactor - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * - * - * This parameter act as bridge from pointwise class to serialize it as a LPE - * parameter - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include "live_effects/parameter/array.h" -#include "live_effects/effect-enum.h" -#include "knot-holder-entity.h" -#include <2geom/pointwise.h> - -namespace Inkscape { - -namespace LivePathEffect { - -class FilletChamferKnotHolderEntity; - -class SatellitePairArrayParam : public ArrayParam > { -public: - SatellitePairArrayParam(const Glib::ustring &label, - const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, - Effect *effect); - virtual ~SatellitePairArrayParam(); - - virtual Gtk::Widget * param_newWidget() { - return NULL; - } - - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); - virtual void set_helper_size(int hs); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror); - virtual void addCanvasIndicators(SPLPEItem const *lpeitem,std::vector &hp_vec); - virtual bool providesKnotHolderEntities() const { - return true; - } - void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); - void set_document_unit(Glib::ustring value_document_unit); - void set_use_distance(bool use_knot_distance ); - void set_unit(const gchar *abbr); - void set_effect_type(EffectType et); - void recalculate_knots(); - virtual void updateCanvasIndicators(); - virtual void updateCanvasIndicators(bool mirror); - void set_pointwise(Geom::Pointwise *pointwise); - friend class FilletChamferKnotHolderEntity; - friend class LPEFilletChamfer; -protected: - KnotHolder *knoth; -private: - SatellitePairArrayParam(const SatellitePairArrayParam &); - SatellitePairArrayParam &operator=(const SatellitePairArrayParam &); - - SPKnotShapeType knot_shape; - SPKnotModeType knot_mode; - guint32 knot_color; - Geom::PathVector hp; - int helper_size; - bool use_distance; - const gchar *unit; - Glib::ustring documentUnit; - EffectType _effectType; - Geom::Pointwise *last_pointwise; - -}; - -class FilletChamferKnotHolderEntity : public KnotHolderEntity { -public: - FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index); - virtual ~FilletChamferKnotHolderEntity() {_pparam->knoth = NULL;} - - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); - virtual Geom::Point knot_get() const; - virtual void knot_click(guint state); - void knot_set_offset(Geom::Satellite); - /** Checks whether the index falls within the size of the parameter's vector */ - bool valid_index(size_t index) const { - return (_pparam->_vector.size() > index); - }; - -private: - SatellitePairArrayParam *_pparam; - size_t _index; -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index 6875799f8..443a48c13 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 533f7af2a..1a40eea9b 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; -- cgit v1.2.3 From ce42be89c9b32edeba6eda6522199ec749e014f8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 12:08:06 +0200 Subject: More cleanup of code structure. TODO: Documentation TODO: Fit code guidelines of Inkscape (bzr r13645.1.64) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index c8ba01bd0..4bacad7ea 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 1696fd366..9018e44f2 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 4926bcc47..9096dff28 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 8b5c275b9..8297143c9 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 54b2fb52f..e873bebf9 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -400,12 +400,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if(pointwise && c->get_segment_count() != segCount && segCount != 0){ pointwise->recalculate_for_new_pwd2(pwd2_in); - pointwise->set_extremes(false, true, 0.0, 0.0); segCount = c->get_segment_count(); } else { pointwise = new Pointwise(pwd2_in, sats); - //mandatory call - pointwise->set_extremes(false, true); segCount = c->get_segment_count(); } satellitearrayparam_values.set_pointwise(pointwise); @@ -422,7 +419,6 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); - pointwise->set_extremes(false, true, 0.0, 0.0); satellitearrayparam_values.set_pointwise(pointwise); } } -- cgit v1.2.3 From aea84844cf40c4c1b1977548421ec50ad164590e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 14:18:34 +0200 Subject: 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(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 4bacad7ea..19991e879 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 9018e44f2..9a40a4f20 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 9096dff28..9e65685ae 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 8297143c9..59ed4d1aa 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 bcd8d1bb3..4680ce2f6 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 73201445a..6304b4148 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 f367bb7f3..d4550b922 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; -- cgit v1.2.3 From f3965759e52107c1cdcd8b7e248e5538fdaa11b6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 17:54:35 +0200 Subject: Added documentation and fix to coding style. (bzr r13645.1.66) --- src/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 ++-- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 80 +-- src/ui/dialog/lpe-fillet-chamfer-properties.h | 54 +- 13 files changed, 1011 insertions(+), 916 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 19991e879..f12004535 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 9a40a4f20..c9d8e2862 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 9e65685ae..cfe93311c 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 59ed4d1aa..3ce1ca75a 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 4680ce2f6..d82cdabe0 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 6304b4148..efe6bb37a 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 d4550b922..df54819fd 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 e873bebf9..6e026550a 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -9,12 +9,12 @@ * Also su_v for his construvtive feedback and time * Also to Mc- (IRC nick) for his important contribution to find real time * values based on - * and finaly to Liam P. White for his big help on coding, that save me a lot of hours + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours * * Released under GNU GPL, read the file 'COPYING' for more information */ - #include "live_effects/lpe-fillet-chamfer.h" #include "helper/geom.h" #include "display/curve.h" @@ -33,29 +33,40 @@ namespace Inkscape { namespace LivePathEffect { static const Util::EnumData FilletMethodData[FM_END] = { - { FM_AUTO, N_("Auto"), "auto" }, - { FM_ARC, N_("Force arc"), "arc" }, + { FM_AUTO, N_("Auto"), "auto" }, { FM_ARC, N_("Force arc"), "arc" }, { FM_BEZIER, N_("Force bezier"), "bezier" } }; -static const Util::EnumDataConverter -FMConverter(FilletMethodData, FM_END); - -LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : - Effect(lpeobject), - satellitearrayparam_values(_("pair_array_param"), _("pair_array_param"), "satellitearrayparam_values", &wr, this), - unit(_("Unit:"), _("Unit"), "unit", &wr, this), - method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), - radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), - chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 1), - flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), - mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "mirror_knots", &wr, this, true), - only_selected(_("Change only selected nodes"), _("Change only selected nodes"), "only_selected", &wr, this, false), - use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false), - hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), - ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), - helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise(NULL), - segCount(0) +static const Util::EnumDataConverter FMConverter(FilletMethodData, + FM_END); + +LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) + : Effect(lpeobject), + satellitearrayparam_values(_("pair_array_param"), _("pair_array_param"), + "satellitearrayparam_values", &wr, this), + unit(_("Unit:"), _("Unit"), "unit", &wr, this), + method(_("Method:"), _("Methods to calculate the fillet or chamfer"), + "method", FMConverter, &wr, this, FM_AUTO), + radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, + this, 0.), + chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", + &wr, this, 1), + flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), + "flexible", &wr, this, false), + mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "mirror_knots", &wr, + this, true), + only_selected(_("Change only selected nodes"), + _("Change only selected nodes"), "only_selected", &wr, this, + false), + use_knot_distance(_("Use knots distance instead radius"), + _("Use knots distance instead radius"), + "use_knot_distance", &wr, this, false), + hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, + false), + ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), + "ignore_radius_0", &wr, this, false), + helper_size(_("Helper size with direction:"), + _("Helper size with direction"), "helper_size", &wr, this, 0), + pointwise(NULL), segment_size(0) { registerParameter(&satellitearrayparam_values); registerParameter(&unit); @@ -83,65 +94,67 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : LPEFilletChamfer::~LPEFilletChamfer() {} - void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) { - SPLPEItem * splpeitem = const_cast(lpeItem); - SPShape * shape = dynamic_cast(splpeitem); + SPLPEItem *splpeitem = const_cast(lpeItem); + SPShape *shape = dynamic_cast(splpeitem); if (shape) { - PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); + PathVector const &original_pathv = + pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - int counterTotal = 0; - std::vector satellites; - for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()){ + int global_counter = 0; + std::vector satellites; + for (PathVector::const_iterator path_it = original_pathv.begin(); + path_it != original_pathv.end(); ++path_it) { + if (path_it->empty()) { continue; } Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Curve &closingline = path_it->back_closed(); - // the closing line segment is always of type - // LineSegment. - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - // closingline.isDegenerate() did not work, because it only checks for - // *exact* zero length, which goes wrong for relative coordinates and - // rounding errors... - // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); - } + const Curve &closingline = path_it->back_closed(); + // the closing line segment is always of type + // LineSegment. + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + // closingline.isDegenerate() did not work, because it only checks for + // *exact* zero length, which goes wrong for relative coordinates and + // rounding errors... + // the closing line segment has zero-length. So stop before that one! + curve_endit = path_it->end_open(); + } } Geom::Path::const_iterator curve_end = curve_endit; --curve_end; int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { - if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ + if ((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()) { g_warning("LPE Fillet not handle degenerate curves."); - SPLPEItem * item = const_cast(lpeItem); + SPLPEItem *item = const_cast(lpeItem); item->removeCurrentPathEffect(false); return; } bool active = true; bool hidden = false; - if (counter==0) { + if (counter == 0) { if (!path_it->closed()) { active = false; } } - Satellite satellite(F, flexible, active, mirror_knots, hidden, 0.0, 0.0, steps); + Satellite satellite(F, flexible, active, mirror_knots, hidden, 0.0, 0.0, + steps); satellites.push_back(satellite); ++curve_it1; counter++; - counterTotal++; + global_counter++; } } - pointwise = new Pointwise( pwd2_in,satellites); - satellitearrayparam_values.set_pointwise(pointwise); + pointwise = new Pointwise(pwd2_in, satellites); + satellitearrayparam_values.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); - SPLPEItem * item = const_cast(lpeItem); + SPLPEItem *item = const_cast(lpeItem); item->removeCurrentPathEffect(false); } } @@ -161,28 +174,36 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Parameter *param = *it; Gtk::Widget *widg = param->param_newWidget(); if (param->param_key == "radius") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); - widg = widgRegistered; + Inkscape::UI::Widget::Scalar *widg_registered = + Gtk::manage(dynamic_cast(widg)); + widg_registered->signal_value_changed() + .connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); + widg = widg_registered; if (widg) { - Gtk::HBox *scalarParameter = dynamic_cast(widg); - std::vector childList = scalarParameter->get_children(); - Gtk::Entry *entryWidg = dynamic_cast(childList[1]); - entryWidg->set_width_chars(6); + Gtk::HBox *scalar_parameter = dynamic_cast(widg); + std::vector childList = + scalar_parameter->get_children(); + Gtk::Entry *entry_widget = dynamic_cast(childList[1]); + entry_widget->set_width_chars(6); } } else if (param->param_key == "chamfer_steps") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateChamferSteps)); - widg = widgRegistered; + Inkscape::UI::Widget::Scalar *widg_registered = + Gtk::manage(dynamic_cast(widg)); + widg_registered->signal_value_changed().connect( + sigc::mem_fun(*this, &LPEFilletChamfer::updateChamferSteps)); + widg = widg_registered; if (widg) { - Gtk::HBox *scalarParameter = dynamic_cast(widg); - std::vector childList = scalarParameter->get_children(); - Gtk::Entry *entryWidg = dynamic_cast(childList[1]); - entryWidg->set_width_chars(3); + Gtk::HBox *scalar_parameter = dynamic_cast(widg); + std::vector childList = + scalar_parameter->get_children(); + Gtk::Entry *entry_widget = dynamic_cast(childList[1]); + entry_widget->set_width_chars(3); } } else if (param->param_key == "helper_size") { - Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast(widg)); - widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); + Inkscape::UI::Widget::Scalar *widg_registered = + Gtk::manage(dynamic_cast(widg)); + widg_registered->signal_value_changed() + .connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); } else if (param->param_key == "only_selected") { Gtk::manage(widg); } @@ -199,32 +220,39 @@ Gtk::Widget *LPEFilletChamfer::newWidget() } ++it; } - - Gtk::HBox *filletContainer = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *fillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); - fillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::fillet)); - - filletContainer->pack_start(*fillet, true, true, 2); - Gtk::Button *inverseFillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); - inverseFillet->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseFillet)); - filletContainer->pack_start(*inverseFillet, true, true, 2); - - Gtk::HBox *chamferContainer = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *chamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); - chamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamfer)); - - chamferContainer->pack_start(*chamfer, true, true, 2); - Gtk::Button *inverseChamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); - inverseChamfer->signal_clicked().connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseChamfer)); - chamferContainer->pack_start(*inverseChamfer, true, true, 2); - - vbox->pack_start(*filletContainer, true, true, 2); - vbox->pack_start(*chamferContainer, true, true, 2); + + Gtk::HBox *fillet_container = Gtk::manage(new Gtk::HBox(true, 0)); + Gtk::Button *fillet = + Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); + fillet->signal_clicked() + .connect(sigc::mem_fun(*this, &LPEFilletChamfer::fillet)); + + fillet_container->pack_start(*fillet, true, true, 2); + Gtk::Button *inverse_fillet = + Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); + inverse_fillet->signal_clicked() + .connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseFillet)); + fillet_container->pack_start(*inverse_fillet, true, true, 2); + + Gtk::HBox *chamfer_container = Gtk::manage(new Gtk::HBox(true, 0)); + Gtk::Button *chamfer = + Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); + chamfer->signal_clicked() + .connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamfer)); + + chamfer_container->pack_start(*chamfer, true, true, 2); + Gtk::Button *inverse_chamfer = + Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); + inverse_chamfer->signal_clicked() + .connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseChamfer)); + chamfer_container->pack_start(*inverse_chamfer, true, true, 2); + + vbox->pack_start(*fillet_container, true, true, 2); + vbox->pack_start(*chamfer_container, true, true, 2); return vbox; } - void LPEFilletChamfer::fillet() { updateSatelliteType(F); @@ -247,7 +275,7 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - if(satellitearrayparam_values.knoth){ + if (satellitearrayparam_values.knoth) { satellitearrayparam_values.knoth->update_knots(); } } @@ -256,81 +284,90 @@ void LPEFilletChamfer::updateAmount() { double power = 0; if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), defaultUnit); + power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), + defaultUnit); } else { - power = radius/100; + power = radius / 100; } std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo pathInfo(pwd2); - for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(!pathInfo.getIsClosed(it - satellites.begin()) && pathInfo.getFirst(it - satellites.begin()) == (unsigned)(it - satellites.begin())){ + Pathinfo path_info(pwd2); + for (std::vector::iterator it = satellites.begin(); + it != satellites.end(); ++it) { + if (!path_info.isClosed(it - satellites.begin()) && + path_info.first(it - satellites.begin()) == + (unsigned)(it - satellites.begin())) { it->amount = 0; continue; } - if(ignore_radius_0 && it->amount == 0){ + if (ignore_radius_0 && it->amount == 0) { continue; } - boost::optional prev = pathInfo.getPrevious(it - satellites.begin()); - boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; - if(prev){ - prevPwd2 = pwd2[*prev]; - prevSat = satellites[*prev]; + boost::optional previous = + path_info.previous(it - satellites.begin()); + boost::optional > previous_d2 = boost::none; + boost::optional previous_satellite = boost::none; + if (previous) { + previous_d2 = pwd2[*previous]; + previous_satellite = satellites[*previous]; } - if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); - if(isNodePointSelected(satPoint)){ - if(!use_knot_distance && !flexible){ - it->amount = it->rad_to_len(power, prevPwd2, pwd2[it - satellites.begin()], prevSat); + if (only_selected) { + Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); + if (isNodePointSelected(satellite_point)) { + if (!use_knot_distance && !flexible) { + it->amount = it->radToLen(power, previous_d2, + pwd2[it - satellites.begin()], previous_satellite); } else { it->amount = power; } } } else { - if(!use_knot_distance && !flexible){ - it->amount = it->rad_to_len(power, prevPwd2, pwd2[it - satellites.begin()], prevSat); + if (!use_knot_distance && !flexible) { + it->amount = it->radToLen(power, previous_d2, + pwd2[it - satellites.begin()], previous_satellite); } else { it->amount = power; } } } pointwise->setSatellites(satellites); - satellitearrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.setPointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() { std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->amount == 0){ + for (std::vector::iterator it = satellites.begin(); + it != satellites.end(); ++it) { + if (ignore_radius_0 && it->amount == 0) { continue; } - if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); - if(isNodePointSelected(satPoint)){ - it->steps = chamfer_steps; + if (only_selected) { + Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); + if (isNodePointSelected(satellite_point)) { + it->steps = chamfer_steps; } } else { it->steps = chamfer_steps; } } pointwise->setSatellites(satellites); - satellitearrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.setPointwise(pointwise); } void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) { std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->amount == 0){ + for (std::vector::iterator it = satellites.begin(); + it != satellites.end(); ++it) { + if (ignore_radius_0 && it->amount == 0) { continue; } - if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); - if(isNodePointSelected(satPoint)){ + if (only_selected) { + Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); + if (isNodePointSelected(satellite_point)) { it->satelliteType = satellitetype; } } else { @@ -338,75 +375,76 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) } } pointwise->setSatellites(satellites); - satellitearrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.setPointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { - SPLPEItem * splpeitem = const_cast(lpeItem); - SPShape * shape = dynamic_cast(splpeitem); + SPLPEItem *splpeitem = const_cast(lpeItem); + SPShape *shape = dynamic_cast(splpeitem); if (shape) { SPCurve *c = shape->getCurve(); - SPPath * path = dynamic_cast(shape); - if(path){ + SPPath *path = dynamic_cast(shape); + if (path) { c = path->get_original_curve(); } //fillet chamfer specific calls - satellitearrayparam_values.set_document_unit(defaultUnit); - satellitearrayparam_values.set_use_distance(use_knot_distance); - satellitearrayparam_values.set_unit(unit.get_abbreviation()); + satellitearrayparam_values.setDocumentUnit(defaultUnit); + satellitearrayparam_values.setUseDistance(use_knot_distance); + satellitearrayparam_values.setUnit(unit.get_abbreviation()); //mandatory call - satellitearrayparam_values.set_effect_type(this->effectType()); - - PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); + satellitearrayparam_values.setEffectType(effectType()); + + PathVector const &original_pathv = + pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector sats = satellitearrayparam_values.data(); + std::vector sats = satellitearrayparam_values.data(); //optional call - if(hide_knots){ - satellitearrayparam_values.set_helper_size(0); + if (hide_knots) { + satellitearrayparam_values.setHelperSize(0); } else { - satellitearrayparam_values.set_helper_size(helper_size); + satellitearrayparam_values.setHelperSize(helper_size); } bool refresh = false; bool hide = true; - for (std::vector::iterator it = sats.begin(); it != sats.end();) - { - if(it->isTime != flexible){ + for (std::vector::iterator it = sats.begin(); + it != sats.end();) { + if (it->isTime != flexible) { it->isTime = flexible; double amount = it->amount; D2 d2_in = pwd2_in[it - sats.begin()]; - if(it->isTime){ - double time = it->toTime(amount,d2_in); + if (it->isTime) { + double time = it->toTime(amount, d2_in); it->amount = time; } else { - double size = it->toSize(amount,d2_in); + double size = it->toSize(amount, d2_in); it->amount = size; } } - if(it->hasMirror != mirror_knots){ + if (it->hasMirror != mirror_knots) { it->hasMirror = mirror_knots; refresh = true; } - if(it->hidden == false){ + if (it->hidden == false) { hide = false; } it->hidden = hide_knots; ++it; } - if(hide != hide_knots){ + if (hide != hide_knots) { refresh = true; } - - if(pointwise && c->get_segment_count() != segCount && segCount != 0){ - pointwise->recalculate_for_new_pwd2(pwd2_in); - segCount = c->get_segment_count(); + + if (pointwise && c->get_segment_count() != segment_size && segment_size != 0) { + pointwise->recalculateForNewPwd2(pwd2_in); + segment_size = c->get_segment_count(); } else { pointwise = new Pointwise(pwd2_in, sats); - segCount = c->get_segment_count(); + segment_size = c->get_segment_count(); } - satellitearrayparam_values.set_pointwise(pointwise); - if(refresh){ + satellitearrayparam_values.setPointwise(pointwise); + if (refresh) { refreshKnots(); } } else { @@ -418,246 +456,272 @@ void LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) { if (!path_in.empty() && pointwise) { - pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); - satellitearrayparam_values.set_pointwise(pointwise); + pointwise->recalculateForNewPwd2(remove_short_cuts( + paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)), 0.01)); + satellitearrayparam_values.setPointwise(pointwise); } } std::vector LPEFilletChamfer::doEffect_path(std::vector const &path_in) { - const double gapHelper = 0.00001; - std::vector pathvector_out; + const double GAP_HELPER = 0.00001; + std::vector path_out; size_t counter = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); + std::vector path_in_processed = + pathv_to_linear_and_cubic_beziers(path_in); for (PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { - if (path_it->empty()){ + if (path_it->empty()) { continue; } - Geom::Path path_out; + Geom::Path tmp_path; Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); Geom::Path::const_iterator curve_endit = path_it->end_default(); - if(path_it->size() == 1){ + if (path_it->size() == 1) { counter++; - path_out.start((*curve_it1).pointAt(0)); - path_out.append(*curve_it1); - pathvector_out.push_back(path_out); + tmp_path.start((*curve_it1).pointAt(0)); + tmp_path.append(*curve_it1); + path_out.push_back(tmp_path); continue; } if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); - // the closing line segment is always of type - // Geom::LineSegment. - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - // closingline.isDegenerate() did not work, because it only checks for - // *exact* zero length, which goes wrong for relative coordinates and - // rounding errors... - // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); - } + const Geom::Curve &closingline = path_it->back_closed(); + // the closing line segment is always of type + // Geom::LineSegment. + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + // closingline.isDegenerate() did not work, because it only checks for + // *exact* zero length, which goes wrong for relative coordinates and + // rounding errors... + // the closing line segment has zero-length. So stop before that one! + curve_endit = path_it->end_open(); + } } - size_t counterCurves = 0; + size_t counter_curves = 0; size_t first = counter; double time0 = 0; std::vector sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { - if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ + if ((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()) { g_warning("LPE Fillet not handle degenerate curves."); return path_in; } Satellite satellite; - Curve *curve_it2Fixed = path_it->begin()->duplicate(); - if(!path_it->closed()){ - if(curve_it2 != curve_endit){ - curve_it2Fixed = (*curve_it2).duplicate(); - if(sats.size()> counter+1 ){ - satellite = sats[counter+1]; + Curve *curve_it2_fixed = path_it->begin()->duplicate(); + if (!path_it->closed()) { + if (curve_it2 != curve_endit) { + curve_it2_fixed = (*curve_it2).duplicate(); + if (sats.size() > counter + 1) { + satellite = sats[counter + 1]; } } else { - if(time0 != 1){ - Curve *lastCurve = curve_it1->portion(time0, 1); - lastCurve->setInitial(path_out.finalPoint()); - path_out.append(*lastCurve); + if (time0 != 1) { + Curve *last_curve = curve_it1->portion(time0, 1); + last_curve->setInitial(tmp_path.finalPoint()); + tmp_path.append(*last_curve); } ++curve_it1; counter++; - counterCurves++; + counter_curves++; continue; } } else { - if(curve_it2 != curve_endit){ - curve_it2Fixed = (*curve_it2).duplicate(); - if(sats.size()> counter+1 ){ - satellite = sats[counter+1]; + if (curve_it2 != curve_endit) { + curve_it2_fixed = (*curve_it2).duplicate(); + if (sats.size() > counter + 1) { + satellite = sats[counter + 1]; } } else { - if(sats.size()> first ){ + if (sats.size() > first) { satellite = sats[first]; } } } - if(first == counter){ - if(sats.size() > first && sats[first].active){ - time0 = sats[first].getTime(path_it->begin()->duplicate()->toSBasis()); + if (first == counter) { + if (sats.size() > first && sats[first].active) { + time0 = + sats[first].time(path_it->begin()->duplicate()->toSBasis()); } else { time0 = 0; } } bool last = curve_it2 == curve_endit; - double s = satellite.getSize(curve_it2Fixed->toSBasis()); - double time1 = satellite.getOpositeTime(s,(*curve_it1).toSBasis()); - double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); - if(!satellite.active){ + double s = satellite.size(curve_it2_fixed->toSBasis()); + double time1 = satellite.time(s, true, (*curve_it1).toSBasis()); + double time2 = satellite.time(curve_it2_fixed->toSBasis()); + if (!satellite.active) { time1 = 1; time2 = 0; } - - if(time1 <= time0){ + + if (time1 <= time0) { time1 = time0; } std::vector times; times.push_back(time0); times.push_back(time1); times.push_back(time2); - Curve *knotCurve1 = curve_it1->portion(times[0], times[1]); - if (counterCurves > 0) { - knotCurve1->setInitial(path_out.finalPoint()); + Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); + if (counter_curves > 0) { + knot_curve_1->setInitial(tmp_path.finalPoint()); } else { - path_out.start((*curve_it1).pointAt(times[0])); - } - - Point startArcPoint = knotCurve1->finalPoint(); - Point endArcPoint = curve_it2Fixed->pointAt(times[2]); - if(times[2] == 1){ - endArcPoint = curve_it2Fixed->pointAt(times[2]-gapHelper); - } - if(times[1] == times[0]){ - startArcPoint = curve_it1->pointAt(times[0]+gapHelper); - } - double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; - double k2 = distance(endArcPoint, curve_it2Fixed->initialPoint()) * K; - Geom::CubicBezier const *cubic1 = dynamic_cast(&*knotCurve1); - Ray ray1(startArcPoint, curve_it1->finalPoint()); - if (cubic1) { - ray1.setPoints((*cubic1)[2], startArcPoint); - } - Point handle1 = Point::polar(ray1.angle(),k1) + startArcPoint; - if(time0 == 1){ - handle1 = startArcPoint; - } - Curve *knotCurve2 = curve_it2Fixed->portion(times[2], 1); - Geom::CubicBezier const *cubic2 = dynamic_cast(&*knotCurve2); - Ray ray2(curve_it2Fixed->initialPoint(), endArcPoint); - if (cubic2) { - ray2.setPoints(endArcPoint, (*cubic2)[1]); - } - Point handle2 = endArcPoint - Point::polar(ray2.angle(),k2); - - bool ccwToggle = cross(curve_it1->finalPoint() - startArcPoint, endArcPoint - startArcPoint) < 0; - double angle = angle_between(ray1, ray2, ccwToggle); - double handleAngle = ray1.angle() - angle; - if (ccwToggle) { - handleAngle = ray1.angle() + angle; - } - Point inverseHandle1 = Point::polar(handleAngle,k1) + startArcPoint; - if(time0 == 1){ - inverseHandle1 = startArcPoint; - } - handleAngle = ray2.angle() + angle; - if (ccwToggle) { - handleAngle = ray2.angle() - angle; - } - Point inverseHandle2 = endArcPoint - Point::polar(handleAngle,k2); - if(times[2] == 1){ - endArcPoint = curve_it2Fixed->pointAt(times[2]); - } - if(times[1] == times[0]){ - startArcPoint = curve_it1->pointAt(times[0]); - } - Line const x_line(Geom::Point(0,0),Geom::Point(1,0)); - Line const angled_line(startArcPoint,endArcPoint); - double angleArc = Geom::angle_between( x_line,angled_line); - double radius = Geom::distance(startArcPoint,middle_point(startArcPoint,endArcPoint))/sin(angle/2.0); + tmp_path.start((*curve_it1).pointAt(times[0])); + } + + Point start_arc_point = knot_curve_1->finalPoint(); + Point end_arc_point = curve_it2_fixed->pointAt(times[2]); + if (times[2] == 1) { + end_arc_point = curve_it2_fixed->pointAt(times[2] - GAP_HELPER); + } + if (times[1] == times[0]) { + start_arc_point = curve_it1->pointAt(times[0] + GAP_HELPER); + } + double k1 = distance(start_arc_point, curve_it1->finalPoint()) * K; + double k2 = distance(end_arc_point, curve_it2_fixed->initialPoint()) * K; + Geom::CubicBezier const *cubic_1 = + dynamic_cast(&*knot_curve_1); + Ray ray_1(start_arc_point, curve_it1->finalPoint()); + if (cubic_1) { + ray_1.setPoints((*cubic_1)[2], start_arc_point); + } + Point handle_1 = Point::polar(ray_1.angle(), k1) + start_arc_point; + if (time0 == 1) { + handle_1 = start_arc_point; + } + Curve *knot_curve_2 = curve_it2_fixed->portion(times[2], 1); + Geom::CubicBezier const *cubic_2 = + dynamic_cast(&*knot_curve_2); + Ray ray_2(curve_it2_fixed->initialPoint(), end_arc_point); + if (cubic_2) { + ray_2.setPoints(end_arc_point, (*cubic_2)[1]); + } + Point handle_2 = end_arc_point - Point::polar(ray_2.angle(), k2); + + bool ccw_toggle = cross(curve_it1->finalPoint() - start_arc_point, + end_arc_point - start_arc_point) < 0; + double angle = angle_between(ray_1, ray_2, ccw_toggle); + double handleAngle = ray_1.angle() - angle; + if (ccw_toggle) { + handleAngle = ray_1.angle() + angle; + } + Point inverse_handle_1 = Point::polar(handleAngle, k1) + start_arc_point; + if (time0 == 1) { + inverse_handle_1 = start_arc_point; + } + handleAngle = ray_2.angle() + angle; + if (ccw_toggle) { + handleAngle = ray_2.angle() - angle; + } + Point inverse_handle_2 = end_arc_point - Point::polar(handleAngle, k2); + if (times[2] == 1) { + end_arc_point = curve_it2_fixed->pointAt(times[2]); + } + if (times[1] == times[0]) { + start_arc_point = curve_it1->pointAt(times[0]); + } + Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); + Line const angled_line(start_arc_point, end_arc_point); + double arc_angle = Geom::angle_between(x_line, angled_line); + double radius = Geom::distance(start_arc_point, + middle_point(start_arc_point, end_arc_point)) / + sin(angle / 2.0); Coord rx = radius; Coord ry = rx; if (times[1] != 1) { - if (times[1] != times[0] || times[1] == times[0] == 1 ) { - if(!knotCurve1->isDegenerate()){ - path_out.append(*knotCurve1); + if (times[1] != times[0] || times[1] == times[0] == 1) { + if (!knot_curve_1->isDegenerate()) { + tmp_path.append(*knot_curve_1); } } SatelliteType type = satellite.satelliteType; size_t steps = satellite.steps; - if(steps < 1){ + if (steps < 1) { steps = 1; } if (type == C) { Geom::Path path_chamfer; - path_chamfer.start(path_out.finalPoint()); - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + path_chamfer.start(tmp_path.finalPoint()); + if ((is_straight_curve(*curve_it1) && + is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + method == FM_ARC) { + path_chamfer.appendNew(rx, ry, arc_angle, 0, + ccw_toggle, end_arc_point); } else { - path_chamfer.appendNew(handle1, handle2, endArcPoint); + path_chamfer.appendNew(handle_1, handle_2, + end_arc_point); } - double chamfer_stepsTime = 1.0/steps; - for(size_t i = 1; i < steps; i++){ - Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); - path_out.appendNew(chamferStep); + double chamfer_stepsTime = 1.0 / steps; + for (size_t i = 1; i < steps; i++) { + Geom::Point chamfer_step = + path_chamfer.pointAt(chamfer_stepsTime * i); + tmp_path.appendNew(chamfer_step); } - path_out.appendNew(endArcPoint); + tmp_path.appendNew(end_arc_point); } else if (type == IC) { Geom::Path path_chamfer; - path_chamfer.start(path_out.finalPoint()); - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - ccwToggle = ccwToggle?0:1; - path_chamfer.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); - }else{ - path_chamfer.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + path_chamfer.start(tmp_path.finalPoint()); + if ((is_straight_curve(*curve_it1) && + is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + method == FM_ARC) { + ccw_toggle = ccw_toggle ? 0 : 1; + path_chamfer.appendNew(rx, ry, arc_angle, 0, + ccw_toggle, end_arc_point); + } else { + path_chamfer.appendNew( + inverse_handle_1, inverse_handle_2, end_arc_point); } - double chamfer_stepsTime = 1.0/steps; - for(size_t i = 1; i < steps; i++){ - Geom::Point chamferStep = path_chamfer.pointAt(chamfer_stepsTime * i); - path_out.appendNew(chamferStep); + double chamfer_stepsTime = 1.0 / steps; + for (size_t i = 1; i < steps; i++) { + Geom::Point chamfer_step = + path_chamfer.pointAt(chamfer_stepsTime * i); + tmp_path.appendNew(chamfer_step); } - path_out.appendNew(endArcPoint); + tmp_path.appendNew(end_arc_point); } else if (type == IF) { - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - ccwToggle = ccwToggle?0:1; - path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); - }else{ - path_out.appendNew(inverseHandle1, inverseHandle2, endArcPoint); + if ((is_straight_curve(*curve_it1) && + is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + method == FM_ARC) { + ccw_toggle = ccw_toggle ? 0 : 1; + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, + end_arc_point); + } else { + tmp_path.appendNew(inverse_handle_1, + inverse_handle_2, end_arc_point); } - } else if (type == F){ - if((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2Fixed) && method != FM_BEZIER )|| method == FM_ARC){ - path_out.appendNew(rx, ry, angleArc, 0, ccwToggle, endArcPoint); + } else if (type == F) { + if ((is_straight_curve(*curve_it1) && + is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + method == FM_ARC) { + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, + end_arc_point); } else { - path_out.appendNew(handle1, handle2, endArcPoint); + tmp_path.appendNew(handle_1, handle_2, + end_arc_point); } } } else { - if(!knotCurve1->isDegenerate()){ - path_out.append(*knotCurve1); + if (!knot_curve_1->isDegenerate()) { + tmp_path.append(*knot_curve_1); } } if (path_it->closed() && last) { - path_out.close(); + tmp_path.close(); } ++curve_it1; if (curve_it2 != curve_endit) { ++curve_it2; } counter++; - counterCurves++; + counter_curves++; time0 = times[2]; } - pathvector_out.push_back(path_out); + path_out.push_back(tmp_path); } - return pathvector_out; + return path_out; } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index e56200a17..c519679f8 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -10,7 +10,8 @@ * Special thanks to Johan Engelen for the base of the effect -powerstroke- * Also to ScislaC for point me to the idea * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of hours + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -36,10 +37,11 @@ public: LPEFilletChamfer(LivePathEffectObject *lpeobject); virtual ~LPEFilletChamfer(); virtual void doBeforeEffect(SPLPEItem const *lpeItem); - virtual std::vector doEffect_path(std::vector const &path_in); + virtual std::vector + doEffect_path(std::vector const &path_in); virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector const &path_in); - virtual Gtk::Widget* newWidget(); + virtual Gtk::Widget *newWidget(); void updateSatelliteType(Geom::SatelliteType satellitetype); void updateChamferSteps(); @@ -49,7 +51,7 @@ public: void inverseChamfer(); void fillet(); void inverseFillet(); - + SatelliteArrayParam satellitearrayparam_values; private: @@ -66,7 +68,7 @@ private: ScalarParam helper_size; Geom::Pointwise *pointwise; - double segCount; + double segment_size; LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 24a491b4b..bac907343 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -19,27 +19,26 @@ // this has to be included last. #include - using namespace Geom; namespace Inkscape { namespace LivePathEffect { -SatelliteArrayParam::SatelliteArrayParam( - const Glib::ustring &label, const Glib::ustring &tip, - const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, - Effect *effect) - : ArrayParam(label, tip, key, wr, effect, 0), - knoth(NULL) +SatelliteArrayParam::SatelliteArrayParam(const Glib::ustring &label, + const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, + Effect *effect) + : ArrayParam(label, tip, key, wr, effect, 0), knoth(NULL) { - knot_shape = SP_KNOT_SHAPE_DIAMOND; - knot_mode = SP_KNOT_MODE_XOR; - knot_color = 0x00ff0000; - helper_size = 0; - use_distance = false; + _knot_shape = SP_KNOT_SHAPE_DIAMOND; + _knot_mode = SP_KNOT_MODE_XOR; + _knot_color = 0x00ff0000; + _helper_size = 0; + _use_distance = false; _effectType = FILLET_CHAMFER; - last_pointwise = NULL; + _last_pointwise = NULL; } SatelliteArrayParam::~SatelliteArrayParam() {} @@ -48,138 +47,141 @@ void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { - knot_shape = shape; - knot_mode = mode; - knot_color = color; + _knot_shape = shape; + _knot_mode = mode; + _knot_color = color; } -void SatelliteArrayParam::set_pointwise(Geom::Pointwise *pointwise) +void SatelliteArrayParam::setPointwise(Geom::Pointwise *pointwise) { - last_pointwise = pointwise; - param_set_and_write_new_value(last_pointwise->getSatellites()); + _last_pointwise = pointwise; + param_set_and_write_new_value(_last_pointwise->getSatellites()); } -void SatelliteArrayParam::set_document_unit(Glib::ustring value_document_unit) +void SatelliteArrayParam::setDocumentUnit(Glib::ustring value_document_unit) { - documentUnit = value_document_unit; + _documentUnit = value_document_unit; } -void SatelliteArrayParam::set_use_distance(bool use_knot_distance ) +void SatelliteArrayParam::setUseDistance(bool use_knot_distance) { - use_distance = use_knot_distance; + _use_distance = use_knot_distance; } -void SatelliteArrayParam::set_unit(const gchar *abbr) +void SatelliteArrayParam::setUnit(const gchar *abbr) { - unit = abbr; + _unit = abbr; } -void SatelliteArrayParam::set_effect_type(EffectType et) +void SatelliteArrayParam::setEffectType(EffectType et) { _effectType = et; } -void SatelliteArrayParam::set_helper_size(int hs) +void SatelliteArrayParam::setHelperSize(int hs) { - helper_size = hs; + _helper_size = hs; updateCanvasIndicators(); } void SatelliteArrayParam::updateCanvasIndicators(bool mirror) { - if(!last_pointwise){ + if (!_last_pointwise) { return; } - Geom::Piecewise > pwd2 = last_pointwise->getPwd2(); - Pathinfo pathInfo(pwd2); - if( mirror == true){ - hp.clear(); + Geom::Piecewise > pwd2 = _last_pointwise->getPwd2(); + Pathinfo path_info(pwd2); + if (mirror == true) { + _hp.clear(); } for (size_t i = 0; i < _vector.size(); ++i) { - if(!_vector[i].active || _vector[i].hidden){ + if (!_vector[i].active || _vector[i].hidden) { continue; } - if((!_vector[i].hasMirror && mirror == true) || _vector[i].amount == 0){ + if ((!_vector[i].hasMirror && mirror == true) || _vector[i].amount == 0) { continue; } double pos = 0; - if(pwd2.size() <= i){ + if (pwd2.size() <= i) { break; } Geom::D2 d2 = pwd2[i]; bool overflow = false; - double size_out = _vector[i].getSize(pwd2[i]); + double size_out = _vector[i].size(pwd2[i]); double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); double lenght_in = 0; - boost::optional d2_prev_index = pathInfo.getPrevious(i); - if(d2_prev_index){ + boost::optional d2_prev_index = path_info.previous(i); + if (d2_prev_index) { lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); } - if(mirror == true){ - if(d2_prev_index){ + if (mirror == true) { + if (d2_prev_index) { d2 = pwd2[*d2_prev_index]; - pos = _vector[i].getOpositeTime(size_out,d2); - if(lenght_out < size_out){ + pos = _vector[i].time(size_out, true, d2); + if (lenght_out < size_out) { overflow = true; } } } else { - pos = _vector[i].getTime(d2); - if(lenght_in < size_out){ + pos = _vector[i].time(d2); + if (lenght_in < size_out) { overflow = true; } } if (pos <= 0 || pos >= 1) { continue; } - Geom::Point ptA = d2.valueAt(pos); - Geom::Point derivA = unit_vector(derivative(d2).valueAt(pos)); + Geom::Point point_a = d2.valueAt(pos); + Geom::Point deriv_a = unit_vector(derivative(d2).valueAt(pos)); Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); - derivA = derivA * rot; - Geom::Point C = ptA - derivA * helper_size; - Geom::Point D = ptA + derivA * helper_size; - Geom::Ray ray1(C, D); - char const * svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; + deriv_a = deriv_a * rot; + Geom::Point point_c = point_a - deriv_a * _helper_size; + Geom::Point point_d = point_a + deriv_a * _helper_size; + Geom::Ray ray_1(point_c, point_d); + char const *svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); Geom::Affine aff = Geom::Affine(); - aff *= Geom::Scale(helper_size); - if(mirror == true){ - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); + aff *= Geom::Scale(_helper_size); + if (mirror == true) { + aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(90)); } else { - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); + aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(270)); } pathv *= aff; pathv += d2.valueAt(pos); - hp.push_back(pathv[0]); - hp.push_back(pathv[1]); - if(overflow){ - double diameter = helper_size; - if(helper_size == 0){ + _hp.push_back(pathv[0]); + _hp.push_back(pathv[1]); + if (overflow) { + double diameter = _helper_size; + if (_helper_size == 0) { diameter = 15; - char const * svgd; - svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; + char const *svgd; + svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 " + "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); - pathv *= Geom::Scale (diameter); - pathv += ptA-Geom::Point(diameter * 0.35,diameter * 0.35); - hp.push_back(pathv[0]); + pathv *= Geom::Scale(diameter); + pathv += point_a - Geom::Point(diameter * 0.35, diameter * 0.35); + _hp.push_back(pathv[0]); } else { - char const * svgd; - svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A 1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 0 -1.32 z"; + char const *svgd; + svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A " + "1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 " + "0 -1.32 z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); aff = Geom::Affine(); - aff *= Geom::Scale(helper_size/2.0); - if(mirror == true){ - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90)); + aff *= Geom::Scale(_helper_size / 2.0); + if (mirror == true) { + aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(90)); } else { - aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270)); + aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(270)); } pathv *= aff; pathv += d2.valueAt(pos); - hp.push_back(pathv[0]); + _hp.push_back(pathv[0]); } } } - if( mirror == true){ + if (mirror == true) { updateCanvasIndicators(false); } } @@ -191,58 +193,47 @@ void SatelliteArrayParam::updateCanvasIndicators() void SatelliteArrayParam::addCanvasIndicators( SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { - hp_vec.push_back(hp); -} - -void SatelliteArrayParam::recalculate_knots() -{ - if(last_pointwise){ - _vector = last_pointwise->getSatellites(); - } + hp_vec.push_back(_hp); } -void -SatelliteArrayParam::param_transform_multiply(Geom::Affine const &postmul, +void SatelliteArrayParam::param_transform_multiply(Geom::Affine const &postmul, bool /*set*/) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/options/transform/rectcorners", true)) { for (size_t i = 0; i < _vector.size(); ++i) { - if(!_vector[i].isTime && _vector[i].amount > 0){ - _vector[i].amount = _vector[i].amount * ((postmul.expansionX() + postmul.expansionY()) / 2); + if (!_vector[i].isTime && _vector[i].amount > 0) { + _vector[i].amount = _vector[i].amount * + ((postmul.expansionX() + postmul.expansionY()) / 2); } } param_set_and_write_new_value(_vector); } - - // param_set_and_write_new_value( (*this) * postmul ); } void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item, - bool mirror) + SPItem *item, bool mirror) { - //recalculate_knots(); for (size_t i = 0; i < _vector.size(); ++i) { size_t iPlus = i; - if( mirror == true){ + if (mirror == true) { iPlus = i + _vector.size(); } - if(!_vector[i].active){ + if (!_vector[i].active) { continue; } - if(!_vector[i].hasMirror && mirror == true){ + if (!_vector[i].hasMirror && mirror == true) { continue; } using namespace Geom; SatelliteType type = _vector[i].satelliteType; //IF is for filletChamfer effect... - if(_effectType == FILLET_CHAMFER){ + if (_effectType == FILLET_CHAMFER) { const gchar *tip; - if (type == C){ - tip = _("Chamfer: Ctrl+Click toggle type, " + if (type == C) { + tip = _("Chamfer: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } else if (type == IC) { @@ -261,11 +252,11 @@ void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, FilletChamferKnotHolderEntity *e = new FilletChamferKnotHolderEntity(this, iPlus); e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); + _knot_shape, _knot_mode, _knot_color); knotholder->add(e); } } - if( mirror == true){ + if (mirror == true) { addKnotHolderEntities(knotholder, desktop, item, false); } } @@ -274,159 +265,155 @@ void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { - knoth = knotholder; - addKnotHolderEntities(knotholder, desktop, item, true); + knoth = knotholder; + addKnotHolderEntities(knotholder, desktop, item, true); } -FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index) - : _pparam(p), - _index(index) -{ -} +FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( + SatelliteArrayParam *p, size_t index) + : _pparam(p), _index(index) {} void FilletChamferKnotHolderEntity::knot_set(Point const &p, - Point const &/*origin*/, - guint state) + Point const &/*origin*/, + guint state) { Geom::Point s = snap_knot_position(p, state); size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); + if (_index >= _pparam->_vector.size()) { + index = _index - _pparam->_vector.size(); } if (!valid_index(index)) { return; } - if( !_pparam->last_pointwise ){ + if (!_pparam->_last_pointwise) { return; } Geom::Satellite satellite = _pparam->_vector.at(index); - if(!satellite.active || satellite.hidden){ + if (!satellite.active || satellite.hidden) { return; } - Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo pathInfo(pwd2); - if(_pparam->_vector.size() <= _index){ - boost::optional d2_prev_index = pathInfo.getPrevious(index); - if(d2_prev_index){ + Pathinfo path_info(pwd2); + if (_pparam->_vector.size() <= _index) { + boost::optional d2_prev_index = path_info.previous(index); + if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; - double mirrorTime = Geom::nearest_point(s, d2_in); - double timeStart = 0; + double mirror_time = Geom::nearest_point(s, d2_in); + double time_start = 0; std::vector sats = pointwise->getSatellites(); - timeStart = sats[*d2_prev_index].getTime(d2_in); - if(timeStart > mirrorTime){ - mirrorTime = timeStart; + time_start = sats[*d2_prev_index].time(d2_in); + if (time_start > mirror_time) { + mirror_time = time_start; } - double size = satellite.toSize(mirrorTime, d2_in); + double size = satellite.toSize(mirror_time, d2_in); double amount = Geom::length(d2_in, Geom::EPSILON) - size; - if(satellite.isTime){ - amount = satellite.toTime(amount,pwd2[index]); + if (satellite.isTime) { + amount = satellite.toTime(amount, pwd2[index]); } satellite.amount = amount; } } else { - satellite.setPosition(s,pwd2[index]); + satellite.setPosition(s, pwd2[index]); } - _pparam->_vector.at(index) = satellite; - SPLPEItem * splpeitem = dynamic_cast(item); - if(splpeitem){ + _pparam->_vector.at(index) = satellite; + SPLPEItem *splpeitem = dynamic_cast(item); + if (splpeitem) { sp_lpe_item_update_patheffect(splpeitem, false, false); } } - -Geom::Point -FilletChamferKnotHolderEntity::knot_get() const +Geom::Point FilletChamferKnotHolderEntity::knot_get() const { - Geom::Point tmpPoint; + Geom::Point tmp_point; size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); + if (_index >= _pparam->_vector.size()) { + index = _index - _pparam->_vector.size(); } if (!valid_index(index)) { return Point(infinity(), infinity()); } Geom::Satellite satellite = _pparam->_vector.at(index); - if(!_pparam->last_pointwise){ + if (!_pparam->_last_pointwise) { return Point(infinity(), infinity()); } - if(!satellite.active || satellite.hidden){ + if (!satellite.active || satellite.hidden) { return Point(infinity(), infinity()); } - Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo pathInfo(pwd2); - if(pwd2.size() <= index){ + Pathinfo path_info(pwd2); + if (pwd2.size() <= index) { return Point(infinity(), infinity()); } this->knot->show(); - if( _index >= _pparam->_vector.size()){ - tmpPoint = satellite.getPosition(pwd2[index]); - boost::optional d2_prev_index = pathInfo.getPrevious(index); - if(d2_prev_index){ - Geom::D2 d2_in = pwd2[*d2_prev_index]; - double s = satellite.getSize(pwd2[index]); - double t = satellite.getOpositeTime(s,d2_in); - if(t > 1){ + if (_index >= _pparam->_vector.size()) { + tmp_point = satellite.getPosition(pwd2[index]); + boost::optional d2_prev_index = path_info.previous(index); + if (d2_prev_index) { + Geom::D2 d2_in = pwd2[*d2_prev_index]; + double s = satellite.size(pwd2[index]); + double t = satellite.time(s, true, d2_in); + if (t > 1) { t = 1; } - if(t < 0){ + if (t < 0) { t = 0; } - double timeStart = 0; - timeStart = pointwise->getSatellites()[*d2_prev_index].getTime(d2_in); - if(timeStart > t){ - t = timeStart; + double time_start = 0; + time_start = pointwise->getSatellites()[*d2_prev_index].time(d2_in); + if (time_start > t) { + t = time_start; } - tmpPoint = (d2_in).valueAt(t); + tmp_point = (d2_in).valueAt(t); } } else { - tmpPoint = satellite.getPosition(pwd2[index]); + tmp_point = satellite.getPosition(pwd2[index]); } - Geom::Point const canvas_point = tmpPoint; + Geom::Point const canvas_point = tmp_point; return canvas_point; } void FilletChamferKnotHolderEntity::knot_click(guint state) { - if( !_pparam->last_pointwise){ + if (!_pparam->_last_pointwise) { return; } size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); + if (_index >= _pparam->_vector.size()) { + index = _index - _pparam->_vector.size(); } if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { _pparam->_vector.at(index).amount = 0.0; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - }else{ + } else { using namespace Geom; SatelliteType type = _pparam->_vector.at(index).satelliteType; - switch(type){ - case F: - type = IF; - break; - case IF: - type = C; - break; - case C: - type = IC; - break; - default: - type = F; - break; + switch (type) { + case F: + type = IF; + break; + case IF: + type = C; + break; + case C: + type = IC; + break; + default: + type = F; + break; } _pparam->_vector.at(index).satelliteType = type; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); const gchar *tip; - if (type == C){ - tip = _("Chamfer: Ctrl+Click toggle type, " + if (type == C) { + tip = _("Chamfer: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } else if (type == IC) { @@ -446,55 +433,63 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - Piecewise > pwd2 = _pparam->last_pointwise->getPwd2(); - Pathinfo pathInfo(pwd2); - double amount = _pparam->_vector.at(index).amount; - if(!_pparam->use_distance && !_pparam->_vector.at(index).isTime){ - boost::optional prev = pathInfo.getPrevious(index); + Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); + Pathinfo path_info(pwd2); + double amount = _pparam->_vector.at(index).amount; + if (!_pparam->_use_distance && !_pparam->_vector.at(index).isTime) { + boost::optional prev = path_info.previous(index); boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; - if(prev){ + boost::optional prevSat = boost::none; + if (prev) { prevPwd2 = pwd2[*prev]; prevSat = _pparam->_vector.at(*prev); } - amount = _pparam->_vector.at(index).len_to_rad(amount, prevPwd2, pwd2[index], prevSat); + amount = _pparam->_vector.at(index) + .lenToRad(amount, prevPwd2, pwd2[index], prevSat); } bool aprox = false; - D2 d2_out = _pparam->last_pointwise->getPwd2()[index]; - boost::optional d2_prev_index = pathInfo.getPrevious(index); - if(d2_prev_index){ - Geom::D2 d2_in = _pparam->last_pointwise->getPwd2()[*d2_prev_index]; - aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->use_distance?true:false; + D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; + boost::optional d2_prev_index = path_info.previous(index); + if (d2_prev_index) { + Geom::D2 d2_in = + _pparam->_last_pointwise->getPwd2()[*d2_prev_index]; + aprox = ((d2_in)[0].degreesOfFreedom() != 2 || + d2_out[0].degreesOfFreedom() != 2) && + !_pparam->_use_distance + ? true + : false; } Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( - this->desktop, amount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index)); - + this->desktop, amount, this, _pparam->_unit, _pparam->_use_distance, + aprox, _pparam->_documentUnit, _pparam->_vector.at(index)); + } } void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) { - if( !_pparam->last_pointwise){ + if (!_pparam->_last_pointwise) { return; } size_t index = _index; - if( _index >= _pparam->_vector.size()){ - index = _index-_pparam->_vector.size(); + if (_index >= _pparam->_vector.size()) { + index = _index - _pparam->_vector.size(); } double amount = satellite.amount; - double maxAmount = amount; - if(!_pparam->use_distance && !satellite.isTime){ - Piecewise > pwd2 = _pparam->last_pointwise->getPwd2(); - Pathinfo pathInfo(pwd2); - boost::optional prev = pathInfo.getPrevious(index); + double max_amount = amount; + if (!_pparam->_use_distance && !satellite.isTime) { + Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); + Pathinfo path_info(pwd2); + boost::optional prev = path_info.previous(index); boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; - if(prev){ + boost::optional prevSat = boost::none; + if (prev) { prevPwd2 = pwd2[*prev]; prevSat = _pparam->_vector.at(*prev); } - amount = _pparam->_vector.at(index).rad_to_len(amount, prevPwd2, pwd2[index], prevSat); - if(maxAmount > 0 && amount == 0){ + amount = _pparam->_vector.at(index) + .radToLen(amount, prevPwd2, pwd2[index], prevSat); + if (max_amount > 0 && amount == 0) { amount = _pparam->_vector.at(index).amount; } } @@ -502,8 +497,8 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) _pparam->_vector.at(index) = satellite; this->parent_holder->knot_ungrabbed_handler(this->knot, 0); _pparam->param_set_and_write_new_value(_pparam->_vector); - SPLPEItem * splpeitem = dynamic_cast(item); - if(splpeitem){ + SPLPEItem *splpeitem = dynamic_cast(item); + if (splpeitem) { sp_lpe_item_update_patheffect(splpeitem, false, false); } } diff --git a/src/live_effects/parameter/satellitearray.h b/src/live_effects/parameter/satellitearray.h index ee0cfbad3..bb53af12b 100644 --- a/src/live_effects/parameter/satellitearray.h +++ b/src/live_effects/parameter/satellitearray.h @@ -10,11 +10,11 @@ * To Nathan Hurst for his review and help on refactor * and finaly to Liam P. White for his big help on coding, that save me a lot of * hours - * - * + * + * * This parameter act as bridge from pointwise class to serialize it as a LPE * parameter - * + * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -32,69 +32,80 @@ class FilletChamferKnotHolderEntity; class SatelliteArrayParam : public ArrayParam { public: - SatelliteArrayParam(const Glib::ustring &label, - const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, - Effect *effect); + SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, Effect *effect); virtual ~SatelliteArrayParam(); - virtual Gtk::Widget * param_newWidget() { + virtual Gtk::Widget *param_newWidget() + { return NULL; } - - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); - virtual void set_helper_size(int hs); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror); - virtual void addCanvasIndicators(SPLPEItem const *lpeitem,std::vector &hp_vec); - virtual bool providesKnotHolderEntities() const { + virtual void setHelperSize(int hs); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, + SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, + SPItem *item, bool mirror); + virtual void addCanvasIndicators(SPLPEItem const *lpeitem, + std::vector &hp_vec); + virtual void updateCanvasIndicators(); + virtual void updateCanvasIndicators(bool mirror); + virtual bool providesKnotHolderEntities() const + { return true; } void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); - void set_document_unit(Glib::ustring value_document_unit); - void set_use_distance(bool use_knot_distance ); - void set_unit(const gchar *abbr); - void set_effect_type(EffectType et); - void recalculate_knots(); - virtual void updateCanvasIndicators(); - virtual void updateCanvasIndicators(bool mirror); - void set_pointwise(Geom::Pointwise *pointwise); + void setDocumentUnit(Glib::ustring value_document__unit); + void setUseDistance(bool use_knot_distance); + void setUnit(const gchar *abbr); + void setEffectType(EffectType et); + void setPointwise(Geom::Pointwise *pointwise); + void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, + guint32 color); + friend class FilletChamferKnotHolderEntity; friend class LPEFilletChamfer; + protected: KnotHolder *knoth; + private: SatelliteArrayParam(const SatelliteArrayParam &); SatelliteArrayParam &operator=(const SatelliteArrayParam &); - SPKnotShapeType knot_shape; - SPKnotModeType knot_mode; - guint32 knot_color; - Geom::PathVector hp; - int helper_size; - bool use_distance; - const gchar *unit; - Glib::ustring documentUnit; + SPKnotShapeType _knot_shape; + SPKnotModeType _knot_mode; + guint32 _knot_color; + Geom::PathVector _hp; + int _helper_size; + bool _use_distance; + const gchar *_unit; + Glib::ustring _documentUnit; EffectType _effectType; - Geom::Pointwise *last_pointwise; + Geom::Pointwise *_last_pointwise; }; class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index); - virtual ~FilletChamferKnotHolderEntity() {_pparam->knoth = NULL;} + virtual ~FilletChamferKnotHolderEntity() + { + _pparam->knoth = NULL; + } - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, + guint state); virtual Geom::Point knot_get() const; virtual void knot_click(guint state); void knot_set_offset(Geom::Satellite); - /** Checks whether the index falls within the size of the parameter's vector */ - bool valid_index(size_t index) const { + /** Checks whether the index falls within the size of the parameter's vector + */ + bool valid_index(size_t index) const + { return (_pparam->_vector.size() > index); - }; + } + ; private: SatelliteArrayParam *_pparam; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index 443a48c13..2960f0d34 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 1a40eea9b..51fc847c3 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( -- cgit v1.2.3 From de70b4b2d0611dbf45ec6adc3f29a36137ce7c42 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 1 Apr 2015 19:26:07 +0200 Subject: Now open -without conversion- old fillet chamfer objects (bzr r13645.1.68) --- src/live_effects/lpe-fillet-chamfer.cpp | 40 ++++++++++++++++++--------------- src/live_effects/lpe-fillet-chamfer.h | 2 +- 2 files changed, 23 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6e026550a..6ff098894 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -41,8 +41,8 @@ static const Util::EnumDataConverter FMConverter(FilletMethodData, LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellitearrayparam_values(_("pair_array_param"), _("pair_array_param"), - "satellitearrayparam_values", &wr, this), + satellites_param(_("pair_array_param"), _("pair_array_param"), + "satellites_param", &wr, this), unit(_("Unit:"), _("Unit"), "unit", &wr, this), method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), @@ -68,7 +68,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) _("Helper size with direction"), "helper_size", &wr, this, 0), pointwise(NULL), segment_size(0) { - registerParameter(&satellitearrayparam_values); + registerParameter(&satellites_param); registerParameter(&unit); registerParameter(&method); registerParameter(&radius); @@ -151,7 +151,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } pointwise = new Pointwise(pwd2_in, satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem *item = const_cast(lpeItem); @@ -275,8 +275,8 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - if (satellitearrayparam_values.knoth) { - satellitearrayparam_values.knoth->update_knots(); + if (satellites_param.knoth) { + satellites_param.knoth->update_knots(); } } @@ -331,7 +331,7 @@ void LPEFilletChamfer::updateAmount() } } pointwise->setSatellites(satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() @@ -353,7 +353,7 @@ void LPEFilletChamfer::updateChamferSteps() } } pointwise->setSatellites(satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) @@ -375,7 +375,7 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) } } pointwise->setSatellites(satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -389,22 +389,26 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } //fillet chamfer specific calls - satellitearrayparam_values.setDocumentUnit(defaultUnit); - satellitearrayparam_values.setUseDistance(use_knot_distance); - satellitearrayparam_values.setUnit(unit.get_abbreviation()); + satellites_param.setDocumentUnit(defaultUnit); + satellites_param.setUseDistance(use_knot_distance); + satellites_param.setUnit(unit.get_abbreviation()); //mandatory call - satellitearrayparam_values.setEffectType(effectType()); + satellites_param.setEffectType(effectType()); PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector sats = satellitearrayparam_values.data(); + std::vector sats = satellites_param.data(); + if(sats.empty()){ + doOnApply(lpeItem); + sats = satellites_param.data(); + } //optional call if (hide_knots) { - satellitearrayparam_values.setHelperSize(0); + satellites_param.setHelperSize(0); } else { - satellitearrayparam_values.setHelperSize(helper_size); + satellites_param.setHelperSize(helper_size); } bool refresh = false; bool hide = true; @@ -443,7 +447,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise = new Pointwise(pwd2_in, sats); segment_size = c->get_segment_count(); } - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); if (refresh) { refreshKnots(); } @@ -458,7 +462,7 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) if (!path_in.empty() && pointwise) { pointwise->recalculateForNewPwd2(remove_short_cuts( paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)), 0.01)); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index c519679f8..dc2199609 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -52,7 +52,7 @@ public: void fillet(); void inverseFillet(); - SatelliteArrayParam satellitearrayparam_values; + SatelliteArrayParam satellites_param; private: UnitParam unit; -- cgit v1.2.3 From e7fc8e1fde0b795b34ab0db85575bbf7c9c11791 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 2 Apr 2015 21:47:51 +0200 Subject: add move knots when move nodes pointed by su_v (bzr r13645.1.69) --- src/live_effects/lpe-fillet-chamfer.cpp | 3 +++ src/live_effects/parameter/satellitearray.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6ff098894..ac412e120 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -405,6 +405,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) sats = satellites_param.data(); } //optional call + if (satellites_param.knoth) { + satellites_param.knoth->update_knots(); + } if (hide_knots) { satellites_param.setHelperSize(0); } else { diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index bac907343..0e42c23c5 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -34,7 +34,7 @@ SatelliteArrayParam::SatelliteArrayParam(const Glib::ustring &label, { _knot_shape = SP_KNOT_SHAPE_DIAMOND; _knot_mode = SP_KNOT_MODE_XOR; - _knot_color = 0x00ff0000; + _knot_color = 0xAAFF8800; _helper_size = 0; _use_distance = false; _effectType = FILLET_CHAMFER; -- cgit v1.2.3 From 323fc5ae45fd8374de4561d0771f6b9d5cd3e87a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 3 Apr 2015 01:46:44 +0200 Subject: Adding suport for duplicate nodes Allow degenrate curves Show helper path whith original path (bzr r13645.1.70) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index cfe93311c..261d2bff4 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 ac412e120..f7fd6f64b 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -129,12 +129,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()) { - g_warning("LPE Fillet not handle degenerate curves."); - SPLPEItem *item = const_cast(lpeItem); - item->removeCurrentPathEffect(false); - return; - } bool active = true; bool hidden = false; if (counter == 0) { @@ -380,6 +374,9 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { + if(!_hp.empty()){ + _hp.clear(); + } SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { @@ -469,6 +466,12 @@ LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) } } +void +LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) +{ + hp_vec.push_back(_hp); +} + std::vector LPEFilletChamfer::doEffect_path(std::vector const &path_in) { @@ -483,6 +486,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (path_it->empty()) { continue; } + _hp.push_back(*path_it); Geom::Path tmp_path; Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); @@ -511,9 +515,15 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double time0 = 0; std::vector sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()) { - g_warning("LPE Fillet not handle degenerate curves."); - return path_in; + if ((*curve_it1).isDegenerate() || (curve_it2 != curve_endit && (*curve_it2).isDegenerate())) { + ++curve_it1; + if (curve_it2 != curve_endit) { + ++curve_it2; + } + counter++; + counter_curves++; + time0 = 0.0; + continue; } Satellite satellite; Curve *curve_it2_fixed = path_it->begin()->duplicate(); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index dc2199609..e3ea41ba8 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -42,7 +42,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector const &path_in); virtual Gtk::Widget *newWidget(); - + void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(Geom::SatelliteType satellitetype); void updateChamferSteps(); void updateAmount(); @@ -69,6 +69,7 @@ private: Geom::Pointwise *pointwise; double segment_size; + Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); -- cgit v1.2.3 From 04218b26ae0a10bf9e64721fb0dd789f024afca5 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 3 Apr 2015 16:10:46 +0200 Subject: Update pathinfo class to allow piecewise and pathvector as input. Add a method on pointwise to allow update if degenerated curves in new path, not noticed by piecewises (bzr r13645.1.72) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index f12004535..f9d4e5dbb 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 c9d8e2862..c41d92e7a 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 261d2bff4..714573ad5 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 3ce1ca75a..48ee36255 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 f7fd6f64b..fdf2469e0 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -66,7 +66,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise(NULL), segment_size(0) + pointwise(NULL) { registerParameter(&satellites_param); registerParameter(&unit); @@ -288,7 +288,7 @@ void LPEFilletChamfer::updateAmount() Pathinfo path_info(pwd2); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if (!path_info.isClosed(it - satellites.begin()) && + if (!path_info.closed(it - satellites.begin()) && path_info.first(it - satellites.begin()) == (unsigned)(it - satellites.begin())) { it->amount = 0; @@ -401,17 +401,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) doOnApply(lpeItem); sats = satellites_param.data(); } - //optional call - if (satellites_param.knoth) { - satellites_param.knoth->update_knots(); - } if (hide_knots) { satellites_param.setHelperSize(0); } else { satellites_param.setHelperSize(helper_size); } - bool refresh = false; - bool hide = true; for (std::vector::iterator it = sats.begin(); it != sats.end();) { if (it->isTime != flexible) { @@ -428,44 +422,22 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } if (it->hasMirror != mirror_knots) { it->hasMirror = mirror_knots; - refresh = true; - } - if (it->hidden == false) { - hide = false; } it->hidden = hide_knots; ++it; } - if (hide != hide_knots) { - refresh = true; - } - - if (pointwise && c->get_segment_count() != segment_size && segment_size != 0) { - pointwise->recalculateForNewPwd2(pwd2_in); - segment_size = c->get_segment_count(); + if (pointwise && c->get_segment_count() != sats.size()) { + pointwise->recalculateForNewPwd2(pwd2_in, original_pathv); } else { pointwise = new Pointwise(pwd2_in, sats); - segment_size = c->get_segment_count(); } satellites_param.setPointwise(pointwise); - if (refresh) { - refreshKnots(); - } + refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } } -void -LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) -{ - if (!path_in.empty() && pointwise) { - pointwise->recalculateForNewPwd2(remove_short_cuts( - paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)), 0.01)); - satellites_param.setPointwise(pointwise); - } -} - void LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index e3ea41ba8..6acc9fb40 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -40,7 +40,6 @@ public: virtual std::vector doEffect_path(std::vector const &path_in); virtual void doOnApply(SPLPEItem const *lpeItem); - virtual void adjustForNewPath(std::vector const &path_in); virtual Gtk::Widget *newWidget(); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(Geom::SatelliteType satellitetype); @@ -68,7 +67,6 @@ private: ScalarParam helper_size; Geom::Pointwise *pointwise; - double segment_size; Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/ui/tool/multi-path-manipulator.cpp b/src/ui/tool/multi-path-manipulator.cpp index f53cef5f4..8a8e4cb8a 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 dbae69f2c..d50c3057b 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); - } - } } } -- cgit v1.2.3 From 49ec02c315e6e5068b1ad395c01db2b536dd9b9e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 3 Apr 2015 21:20:55 +0200 Subject: Updated Pathinfo to discrimine degenerate curves optionaly. Fixed redundant data in are_near from pointwise Fixed Fillet-Chamfer lpe to allow duplicate nodes (bzr r13645.1.73) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index f9d4e5dbb..a37c0e475 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 c41d92e7a..021fcca2b 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 714573ad5..f68c9b13f 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 fdf2469e0..6cc9062d9 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -487,11 +487,11 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double time0 = 0; std::vector sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() || (curve_it2 != curve_endit && (*curve_it2).isDegenerate())) { + if (curve_it2 != curve_endit && (*curve_it2).isDegenerate()) { + ++curve_it2; + } + if ((*curve_it1).isDegenerate()) { ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } counter++; counter_curves++; time0 = 0.0; -- cgit v1.2.3 From f4864a7048b05cfe032027470c58e5ef2b69bd59 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 17:21:27 +0200 Subject: Fix a bug in pathinfo (bzr r13645.1.74) --- src/helper/geom-pathinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index a37c0e475..99ca3c8aa 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 */ -- cgit v1.2.3 From c6457829dc2711fca07f5f27ecc597dc4f932929 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 17:59:57 +0200 Subject: fixing bug on closed paths (bzr r13645.1.76) --- src/helper/geom-pathinfo.cpp | 2 +- src/live_effects/lpe-fillet-chamfer.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 99ca3c8aa..a37c0e475 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 6cc9062d9..ac877c792 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -427,6 +427,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) ++it; } if (pointwise && c->get_segment_count() != sats.size()) { + std::cout << "recalculta\n"; pointwise->recalculateForNewPwd2(pwd2_in, original_pathv); } else { pointwise = new Pointwise(pwd2_in, sats); -- cgit v1.2.3 From 22ded87a8ca58e0ff4400b2d4e76787f4ac22bd6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 19:39:38 +0200 Subject: Fixed bug on closed paths, Clenup of pathinfo (bzr r13645.1.77) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index a37c0e475..ac94c0281 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 021fcca2b..7a597202f 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 ac877c792..935e97ec9 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -426,8 +426,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) it->hidden = hide_knots; ++it; } - if (pointwise && c->get_segment_count() != sats.size()) { - std::cout << "recalculta\n"; + Pathinfo path_info(original_pathv); + size_t number_curves = path_info.numberCurves() + 1; + if (pointwise && number_curves != sats.size()) { pointwise->recalculateForNewPwd2(pwd2_in, original_pathv); } else { pointwise = new Pointwise(pwd2_in, sats); -- cgit v1.2.3 From 74649824e41b26bcf560ba485364a6ffe7b80fca Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Apr 2015 20:12:48 +0200 Subject: rename pathinfo function (bzr r13645.1.78) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index ac94c0281..0cb7c64dd 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 7a597202f..73220b959 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 f68c9b13f..54cfbb45d 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 935e97ec9..cad67cea9 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -427,7 +427,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) ++it; } Pathinfo path_info(original_pathv); - size_t number_curves = path_info.numberCurves() + 1; + size_t number_curves = path_info.size(); if (pointwise && number_curves != sats.size()) { pointwise->recalculateForNewPwd2(pwd2_in, original_pathv); } else { -- cgit v1.2.3 From 1a4fb1c5b0c91ed84f3a98bc78cfc725d043e629 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 7 Apr 2015 00:22:14 +0200 Subject: Adding and renaming methofs to pathinfo (bzr r13645.1.79) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 0cb7c64dd..8144564cb 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 73220b959..85c4ca6fa 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 54cfbb45d..5b153841b 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 48ee36255..e4b9f2b05 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 cad67cea9..a846e4bad 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -429,7 +429,16 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Pathinfo path_info(original_pathv); size_t number_curves = path_info.size(); if (pointwise && number_curves != sats.size()) { - pointwise->recalculateForNewPwd2(pwd2_in, original_pathv); + bool active = true; + bool hidden = false; + bool is_time = sats[0].isTime; + bool mirror_knots = sats[0].hasMirror; + double amount = 0.0; + double degrees = 0.0; + int steps = 0; + Satellite sat(sats[0].satelliteType, is_time, active, mirror_knots, + hidden, amount, degrees, steps); + pointwise->recalculateForNewPwd2(pwd2_in, original_pathv, sat); } else { pointwise = new Pointwise(pwd2_in, sats); } -- cgit v1.2.3 From b0de25aa4da8128cb2c3b8b92b67db5070c5ef72 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 7 Apr 2015 00:25:02 +0200 Subject: added comment (bzr r13645.1.80) --- src/helper/geom-pointwise.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 5b153841b..6521e10b2 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--; -- cgit v1.2.3 From f3f25749ce81d3664a53e723c611645f78bdefa2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 22 Apr 2015 18:47:54 +0200 Subject: 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(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 8144564cb..38d58d417 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 6521e10b2..74c594d68 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 e4b9f2b05..590f25f6f 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); -- cgit v1.2.3 From 81dd40474313f2adbb1f59fb4ad9a38342f03752 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 22 Apr 2015 20:51:06 +0200 Subject: 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(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 74c594d68..89bde4130 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 590f25f6f..e4b9f2b05 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); -- cgit v1.2.3 From 3ce6cb91e8259ec064956c79c2cc4f9050dccbce Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 9 May 2015 22:48:48 +0200 Subject: fixing review (bzr r13645.1.86) --- src/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 (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 38d58d417..9e5e409c3 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 85c4ca6fa..ae05f5b89 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 89bde4130..bd03f1d89 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 e4b9f2b05..787cdbfff 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 d82cdabe0..000000000 --- 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 efe6bb37a..397a556a9 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 df54819fd..263cefa68 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 1b7f232ed..d26f47541 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -97,12 +97,12 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { - PathVector const &original_pathv = + PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int global_counter = 0; - std::vector satellites; + std::vector satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) { @@ -111,7 +111,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Curve &closingline = path_it->back_closed(); + Curve const &closingline = path_it->back_closed(); // the closing line segment is always of type // LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { @@ -168,13 +168,12 @@ Gtk::Widget *LPEFilletChamfer::newWidget() if (param->param_key == "radius") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); - widg_registered->signal_value_changed() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); + widg_registered->signal_value_changed().connect( + sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); widg = widg_registered; if (widg) { Gtk::HBox *scalar_parameter = dynamic_cast(widg); - std::vector childList = - scalar_parameter->get_children(); + std::vector childList = scalar_parameter->get_children(); Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(6); } @@ -186,16 +185,15 @@ Gtk::Widget *LPEFilletChamfer::newWidget() widg = widg_registered; if (widg) { Gtk::HBox *scalar_parameter = dynamic_cast(widg); - std::vector childList = - scalar_parameter->get_children(); + std::vector childList = scalar_parameter->get_children(); Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(3); } } else if (param->param_key == "helper_size") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); - widg_registered->signal_value_changed() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); + widg_registered->signal_value_changed().connect( + sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); } else if (param->param_key == "only_selected") { Gtk::manage(widg); } @@ -280,10 +278,10 @@ void LPEFilletChamfer::updateAmount() } else { power = radius / 100; } - std::vector satellites = pointwise->getSatellites(); + std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); Pathinfo path_info(pwd2); - for (std::vector::iterator it = satellites.begin(); + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (!path_info.closed(it - satellites.begin()) && path_info.first(it - satellites.begin()) == @@ -297,7 +295,7 @@ void LPEFilletChamfer::updateAmount() boost::optional previous = path_info.previous(it - satellites.begin()); boost::optional > previous_d2 = boost::none; - boost::optional previous_satellite = boost::none; + boost::optional previous_satellite = boost::none; if (previous) { previous_d2 = pwd2[*previous]; previous_satellite = satellites[*previous]; @@ -327,9 +325,9 @@ void LPEFilletChamfer::updateAmount() void LPEFilletChamfer::updateChamferSteps() { - std::vector satellites = pointwise->getSatellites(); + std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (ignore_radius_0 && it->amount == 0) { continue; @@ -347,11 +345,11 @@ void LPEFilletChamfer::updateChamferSteps() satellites_param.setPointwise(pointwise); } -void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) +void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - std::vector satellites = pointwise->getSatellites(); + std::vector satellites = pointwise->getSatellites(); Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (ignore_radius_0 && it->amount == 0) { continue; @@ -391,7 +389,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector sats = satellites_param.data(); + std::vector sats = satellites_param.data(); if(sats.empty()){ doOnApply(lpeItem); sats = satellites_param.data(); @@ -491,7 +489,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) size_t counter_curves = 0; size_t first = counter; double time0 = 0; - std::vector sats = pointwise->getSatellites(); + std::vector sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { if (curve_it2 != curve_endit && (*curve_it2).isDegenerate()) { ++curve_it2; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 9ec5b5e04..48056924a 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -41,7 +41,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual Gtk::Widget *newWidget(); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); - void updateSatelliteType(Geom::SatelliteType satellitetype); + void updateSatelliteType(SatelliteType satellitetype); void updateChamferSteps(); void updateAmount(); void refreshKnots(); @@ -64,7 +64,7 @@ private: BoolParam ignore_radius_0; ScalarParam helper_size; - Geom::Pointwise *pointwise; + Pointwise *pointwise; Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index c8ee63fec..c71b8ed55 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -15,16 +15,16 @@ namespace LivePathEffect { //TODO: move maybe to svg-lenght.cpp unsigned int -sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ +sp_svg_satellite_read_d(gchar const *str, Satellite *sat){ if (!str) { return 0; } gchar ** strarray = g_strsplit(str, ",", 8); if(strarray[7] && !strarray[8]){ sat->setSatelliteType(g_strstrip(strarray[0])); - sat->isTime = strncmp(strarray[1],"1",1) == 0; + sat->is_time = strncmp(strarray[1],"1",1) == 0; sat->active = strncmp(strarray[2],"1",1) == 0; - sat->hasMirror = strncmp(strarray[3],"1",1) == 0; + sat->has_mirror = strncmp(strarray[3],"1",1) == 0; sat->hidden = strncmp(strarray[4],"1",1) == 0; double amount,angle; float stepsTmp; @@ -76,14 +76,14 @@ ArrayParam::readsvg(const gchar * str) } template <> -Geom::Satellite -ArrayParam::readsvg(const gchar * str) +Satellite +ArrayParam::readsvg(const gchar * str) { - Geom::Satellite sat; + Satellite sat; if (sp_svg_satellite_read_d(str, &sat)) { return sat; } - Geom::Satellite satellite(Geom::F, true, false, false, true, 0.0, 0.0, 0); + Satellite satellite(Geom::F, true, false, false, true, 0.0, 0.0, 0); return satellite; } diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 25e479304..66ed6344b 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -16,7 +16,6 @@ #include "live_effects/parameter/parameter.h" #include "helper/geom-satellite.h" -#include "helper/geom-satellite-enum.h" #include "svg/svg.h" #include "svg/stringstream.h" @@ -111,14 +110,14 @@ protected: str << nVector; } - void writesvgData(SVGOStringStream &str, Geom::Satellite const &nVector) const { + void writesvgData(SVGOStringStream &str, Satellite const &nVector) const { str << nVector.getSatelliteTypeGchar(); str << ","; - str << nVector.isTime; + str << nVector.is_time; str << ","; str << nVector.active; str << ","; - str << nVector.hasMirror; + str << nVector.has_mirror; str << ","; str << nVector.hidden; str << ","; diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index b0b036962..5a3b64dd3 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -30,7 +30,7 @@ SatelliteArrayParam::SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayParam(label, tip, key, wr, effect, 0), knoth(NULL) + : ArrayParam(label, tip, key, wr, effect, 0), knoth(NULL) { _knot_shape = SP_KNOT_SHAPE_DIAMOND; _knot_mode = SP_KNOT_MODE_XOR; @@ -52,7 +52,7 @@ void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, _knot_color = color; } -void SatelliteArrayParam::setPointwise(Geom::Pointwise *pointwise) +void SatelliteArrayParam::setPointwise(Pointwise *pointwise) { _last_pointwise = pointwise; param_set_and_write_new_value(_last_pointwise->getSatellites()); @@ -280,11 +280,11 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, return; } - Geom::Satellite satellite = _pparam->_vector.at(index); + Satellite satellite = _pparam->_vector.at(index); if (!satellite.active || satellite.hidden) { return; } - Geom::Pointwise *pointwise = _pparam->_last_pointwise; + Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); Pathinfo path_info(pwd2); if (_pparam->_vector.size() <= _index) { @@ -293,7 +293,7 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, Geom::D2 d2_in = pwd2[*d2_prev_index]; double mirror_time = Geom::nearest_point(s, d2_in); double time_start = 0; - std::vector sats = pointwise->getSatellites(); + std::vector sats = pointwise->getSatellites(); time_start = sats[*d2_prev_index].time(d2_in); if (time_start > mirror_time) { mirror_time = time_start; @@ -325,14 +325,14 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const if (!valid_index(index)) { return Point(infinity(), infinity()); } - Geom::Satellite satellite = _pparam->_vector.at(index); + Satellite satellite = _pparam->_vector.at(index); if (!_pparam->_last_pointwise) { return Point(infinity(), infinity()); } if (!satellite.active || satellite.hidden) { return Point(infinity(), infinity()); } - Geom::Pointwise *pointwise = _pparam->_last_pointwise; + Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); Pathinfo path_info(pwd2); if (pwd2.size() <= index) { @@ -429,7 +429,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) if (!_pparam->_use_distance && !_pparam->_vector.at(index).isTime) { boost::optional prev = path_info.previous(index); boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; + boost::optional prevSat = boost::none; if (prev) { prevPwd2 = pwd2[*prev]; prevSat = _pparam->_vector.at(*prev); @@ -456,7 +456,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } -void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) +void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) { if (!_pparam->_last_pointwise) { return; @@ -472,7 +472,7 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) Pathinfo path_info(pwd2); boost::optional prev = path_info.previous(index); boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; + boost::optional prevSat = boost::none; if (prev) { prevPwd2 = pwd2[*prev]; prevSat = _pparam->_vector.at(*prev); diff --git a/src/live_effects/parameter/satellitearray.h b/src/live_effects/parameter/satellitearray.h index 2845e3969..cc09e7589 100644 --- a/src/live_effects/parameter/satellitearray.h +++ b/src/live_effects/parameter/satellitearray.h @@ -30,7 +30,7 @@ namespace LivePathEffect { class FilletChamferKnotHolderEntity; -class SatelliteArrayParam : public ArrayParam { +class SatelliteArrayParam : public ArrayParam { public: SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, @@ -57,7 +57,7 @@ public: void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); void setEffectType(EffectType et); - void setPointwise(Geom::Pointwise *pointwise); + void setPointwise(Pointwise *pointwise); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); @@ -78,7 +78,7 @@ private: int _helper_size; bool _use_distance; EffectType _effectType; - Geom::Pointwise *_last_pointwise; + Pointwise *_last_pointwise; }; @@ -94,7 +94,7 @@ public: guint state); virtual Geom::Point knot_get() const; virtual void knot_click(guint state); - void knot_set_offset(Geom::Satellite); + void knot_set_offset(Satellite); /** Checks whether the index falls within the size of the parameter's vector */ bool valid_index(size_t index) const -- cgit v1.2.3 From 6195a5fd157ff2681534aa90a279627e0048d4e1 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 00:37:31 +0200 Subject: fixing review (bzr r13645.1.87) --- src/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 ++++------ src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 4 +- src/ui/dialog/lpe-fillet-chamfer-properties.h | 6 +-- 6 files changed, 92 insertions(+), 87 deletions(-) (limited to 'src') diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 397a556a9..51cff7d79 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 263cefa68..a4b1b23b9 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 d26f47541..8d457c90b 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -20,7 +20,6 @@ #include "display/curve.h" #include "helper/geom-curves.h" #include "helper/geom-satellite.h" -#include "helper/geom-satellite-enum.h" #include "helper/geom-pathinfo.h" #include <2geom/svg-elliptical-arc.h> #include "knotholder.h" @@ -134,8 +133,14 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, active, mirror_knots, hidden, 0.0, 0.0, - steps); + Satellite satellite(F); + satellite.setIsTime(flexible); + satellite.setActive(active) + satellite.setMirror(mirror_knots) + satellite.setHidden(hidden) + satellite.setAmount(0.0); + satellite.setAngle(0.0); + satellite.setSteps(steps); satellites.push_back(satellite); ++curve_it1; counter++; @@ -282,10 +287,12 @@ void LPEFilletChamfer::updateAmount() Piecewise > pwd2 = pointwise->getPwd2(); Pathinfo path_info(pwd2); for (std::vector::iterator it = satellites.begin(); - it != satellites.end(); ++it) { + it != satellites.end(); ++it) + { if (!path_info.closed(it - satellites.begin()) && path_info.first(it - satellites.begin()) == - (unsigned)(it - satellites.begin())) { + (unsigned)(it - satellites.begin())) + { it->amount = 0; continue; } @@ -294,26 +301,28 @@ void LPEFilletChamfer::updateAmount() } boost::optional previous = path_info.previous(it - satellites.begin()); - boost::optional > previous_d2 = boost::none; - boost::optional previous_satellite = boost::none; - if (previous) { - previous_d2 = pwd2[*previous]; - previous_satellite = satellites[*previous]; - } if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { if (!use_knot_distance && !flexible) { - it->amount = it->radToLen(power, previous_d2, - pwd2[it - satellites.begin()], previous_satellite); + if(previous){ + it->amount = it->radToLen(power, pwd2[*previous], + pwd2[it - satellites.begin()], satellites[*previous]); + } else { + it->amount = 0.0; + } } else { it->amount = power; } } } else { if (!use_knot_distance && !flexible) { - it->amount = it->radToLen(power, previous_d2, - pwd2[it - satellites.begin()], previous_satellite); + if(previous){ + it->amount = it->radToLen(power, pwd2[*previous], + pwd2[it - satellites.begin()], satellites[*previous]); + } else { + it->amount = 0.0; + } } else { it->amount = power; } @@ -406,10 +415,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) double amount = it->amount; D2 d2_in = pwd2_in[it - sats.begin()]; if (it->isTime) { - double time = it->toTime(amount, d2_in); + double time = it->timeAtArcLength(amount, d2_in); it->amount = time; } else { - double size = it->toSize(amount, d2_in); + double size = it->arcLengthAt(amount, d2_in); it->amount = size; } } diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 5a3b64dd3..5a90d1930 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -298,10 +298,10 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, if (time_start > mirror_time) { mirror_time = time_start; } - double size = satellite.toSize(mirror_time, d2_in); + double size = satellite.arcLengthAt(mirror_time, d2_in); double amount = Geom::length(d2_in, Geom::EPSILON) - size; if (satellite.isTime) { - amount = satellite.toTime(amount, pwd2[index]); + amount = satellite.timeAtArcLength(amount, pwd2[index]); } satellite.amount = amount; } @@ -428,14 +428,11 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) double amount = _pparam->_vector.at(index).amount; if (!_pparam->_use_distance && !_pparam->_vector.at(index).isTime) { boost::optional prev = path_info.previous(index); - boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; if (prev) { - prevPwd2 = pwd2[*prev]; - prevSat = _pparam->_vector.at(*prev); + amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*prev], pwd2[index],_pparam->_vector.at(*prev)); + } else { + amount = 0.0; } - amount = _pparam->_vector.at(index) - .lenToRad(amount, prevPwd2, pwd2[index], prevSat); } bool aprox = false; D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; @@ -471,14 +468,11 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); Pathinfo path_info(pwd2); boost::optional prev = path_info.previous(index); - boost::optional > prevPwd2 = boost::none; - boost::optional prevSat = boost::none; if (prev) { - prevPwd2 = pwd2[*prev]; - prevSat = _pparam->_vector.at(*prev); + amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index], _pparam->_vector.at(*prev)); + } else { + amount = 0.0; } - amount = _pparam->_vector.at(index) - .radToLen(amount, prevPwd2, pwd2[index], prevSat); if (max_amount > 0 && amount == 0) { amount = _pparam->_vector.at(index).amount; } diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index bc6557b19..2b49d1952 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 53bb90b80..f982db286 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; -- cgit v1.2.3 From 870dbb0348163f55263eb9dca601d525d53a8d79 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 13:40:31 +0200 Subject: Working on Krzysztof review. Seems to be all fixed. TODO: double check review and comment (bzr r13645.1.89) --- src/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 +++++++------- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 18 +-- 13 files changed, 249 insertions(+), 245 deletions(-) (limited to 'src') diff --git a/src/helper/Makefile_insert b/src/helper/Makefile_insert index 1d051734e..919234b47 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 9e5e409c3..5ffd1d31e 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 ae05f5b89..8a6c51e51 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 bd03f1d89..3041c60ea 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 787cdbfff..b1f2235c6 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 51cff7d79..c2d4ef715 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 a4b1b23b9..722adbef4 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 e06afef2f..a5bb1741c 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -58,11 +58,11 @@ set(live_effects_SRC parameter/array.cpp parameter/bool.cpp - parameter/parameter.cpp - parameter/path.cpp parameter/originalpath.cpp parameter/originalpatharray.cpp + parameter/parameter.cpp parameter/path-reference.cpp + parameter/path.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp parameter/satellitearray.cpp diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 8d457c90b..16bef6a99 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -4,13 +4,6 @@ * * Copyright (C) 2014 Author(s) * - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * Also to Mc- (IRC nick) for his important contribution to find real time - * values based on - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -27,7 +20,6 @@ // TODO due to internal breakage in glibmm headers, this must be last: #include -using namespace Geom; namespace Inkscape { namespace LivePathEffect { @@ -45,7 +37,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, - this, 0.), + this, 0.0), chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 1), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), @@ -78,7 +70,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) registerParameter(&only_selected); registerParameter(&hide_knots); - radius.param_set_range(0., infinity()); + radius.param_set_range(0.0, Geom::infinity()); radius.param_set_increments(1, 1); radius.param_set_digits(4); chamfer_steps.param_set_range(1, 999); @@ -96,13 +88,13 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { - PathVector const original_pathv = + Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); + Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int global_counter = 0; std::vector satellites; - for (PathVector::const_iterator path_it = original_pathv.begin(); + for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) { continue; @@ -110,7 +102,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - Curve const &closingline = path_it->back_closed(); + Geom::Curve const &closingline = path_it->back_closed(); // the closing line segment is always of type // LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { @@ -133,11 +125,11 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F); + Satellite satellite(FILLET); satellite.setIsTime(flexible); - satellite.setActive(active) - satellite.setMirror(mirror_knots) - satellite.setHidden(hidden) + satellite.setActive(active); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hidden); satellite.setAmount(0.0); satellite.setAngle(0.0); satellite.setSteps(steps); @@ -148,6 +140,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } pointwise = new Pointwise(pwd2_in, satellites); + pointwise->setPathInfo(original_pathv); satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -250,22 +243,22 @@ Gtk::Widget *LPEFilletChamfer::newWidget() void LPEFilletChamfer::fillet() { - updateSatelliteType(F); + updateSatelliteType(FILLET); } void LPEFilletChamfer::inverseFillet() { - updateSatelliteType(IF); + updateSatelliteType(INVERSE_FILLET); } void LPEFilletChamfer::chamfer() { - updateSatelliteType(C); + updateSatelliteType(CHAMFER); } void LPEFilletChamfer::inverseChamfer() { - updateSatelliteType(IC); + updateSatelliteType(INVERSE_CHAMFER); } void LPEFilletChamfer::refreshKnots() @@ -284,7 +277,7 @@ void LPEFilletChamfer::updateAmount() power = radius / 100; } std::vector satellites = pointwise->getSatellites(); - Piecewise > pwd2 = pointwise->getPwd2(); + Geom::Piecewise > pwd2 = pointwise->getPwd2(); Pathinfo path_info(pwd2); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) @@ -335,7 +328,7 @@ void LPEFilletChamfer::updateAmount() void LPEFilletChamfer::updateChamferSteps() { std::vector satellites = pointwise->getSatellites(); - Piecewise > pwd2 = pointwise->getPwd2(); + Geom::Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (ignore_radius_0 && it->amount == 0) { @@ -357,7 +350,7 @@ void LPEFilletChamfer::updateChamferSteps() void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { std::vector satellites = pointwise->getSatellites(); - Piecewise > pwd2 = pointwise->getPwd2(); + Geom::Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (ignore_radius_0 && it->amount == 0) { @@ -366,10 +359,10 @@ void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { - it->satelliteType = satellitetype; + it->satellite_type = satellitetype; } } else { - it->satelliteType = satellitetype; + it->satellite_type = satellitetype; } } pointwise->setSatellites(satellites); @@ -394,9 +387,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //mandatory call satellites_param.setEffectType(effectType()); - PathVector const &original_pathv = + Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); + Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); std::vector sats = satellites_param.data(); if(sats.empty()){ @@ -410,20 +403,20 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } for (std::vector::iterator it = sats.begin(); it != sats.end();) { - if (it->isTime != flexible) { - it->isTime = flexible; + if (it->is_time != flexible) { + it->is_time = flexible; double amount = it->amount; - D2 d2_in = pwd2_in[it - sats.begin()]; - if (it->isTime) { - double time = it->timeAtArcLength(amount, d2_in); + Geom::D2 d2_in = pwd2_in[it - sats.begin()]; + if (it->is_time) { + double time = timeAtArcLength(amount, d2_in); it->amount = time; } else { - double size = it->arcLengthAt(amount, d2_in); + double size = arcLengthAt(amount, d2_in); it->amount = size; } } - if (it->hasMirror != mirror_knots) { - it->hasMirror = mirror_knots; + if (it->has_mirror != mirror_knots) { + it->has_mirror = mirror_knots; } it->hidden = hide_knots; ++it; @@ -431,19 +424,19 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Pathinfo path_info(original_pathv); size_t number_curves = path_info.size(); if (pointwise && number_curves != sats.size()) { - bool active = true; - bool hidden = false; - bool is_time = sats[0].isTime; - bool mirror_knots = sats[0].hasMirror; - double amount = 0.0; - double degrees = 0.0; - int steps = 0; - Satellite sat(sats[0].satelliteType, is_time, active, mirror_knots, - hidden, amount, degrees, steps); + Satellite sat(sats[0].satellite_type); + sat.setIsTime(sats[0].is_time); + sat.setActive(true); + sat.setHasMirror( sats[0].has_mirror); + sat.setHidden(false); + sat.setAmount(0.0); + sat.setAngle(0.0); + sat.setSteps(0); pointwise->recalculateForNewPwd2(pwd2_in, original_pathv, sat); } else { pointwise = new Pointwise(pwd2_in, sats); } + pointwise->setPathInfo(original_pathv); satellites_param.setPointwise(pointwise); refreshKnots(); } else { @@ -466,7 +459,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); std::vector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); - for (PathVector::const_iterator path_it = path_in_processed.begin(); + for (Geom::PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { if (path_it->empty()) { continue; @@ -511,7 +504,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) continue; } Satellite satellite; - Curve *curve_it2_fixed = path_it->begin()->duplicate(); + Geom::Curve *curve_it2_fixed = path_it->begin()->duplicate(); if (!path_it->closed()) { if (curve_it2 != curve_endit) { curve_it2_fixed = (*curve_it2).duplicate(); @@ -520,7 +513,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } } else { if (time0 != 1) { - Curve *last_curve = curve_it1->portion(time0, 1); + Geom::Curve *last_curve = curve_it1->portion(time0, 1); last_curve->setInitial(tmp_path.finalPoint()); tmp_path.append(*last_curve); } @@ -552,7 +545,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } bool last = curve_it2 == curve_endit; - double s = satellite.size(curve_it2_fixed->toSBasis()); + double s = satellite.arcDistance(curve_it2_fixed->toSBasis()); double time1 = satellite.time(s, true, (*curve_it1).toSBasis()); double time2 = satellite.time(curve_it2_fixed->toSBasis()); if (!satellite.active) { @@ -567,15 +560,15 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) times.push_back(time0); times.push_back(time1); times.push_back(time2); - Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); + Geom::Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); if (counter_curves > 0) { knot_curve_1->setInitial(tmp_path.finalPoint()); } else { tmp_path.start((*curve_it1).pointAt(times[0])); } - Point start_arc_point = knot_curve_1->finalPoint(); - Point end_arc_point = curve_it2_fixed->pointAt(times[2]); + Geom::Point start_arc_point = knot_curve_1->finalPoint(); + Geom::Point end_arc_point = curve_it2_fixed->pointAt(times[2]); if (times[2] == 1) { end_arc_point = curve_it2_fixed->pointAt(times[2] - GAP_HELPER); } @@ -586,22 +579,22 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double k2 = distance(end_arc_point, curve_it2_fixed->initialPoint()) * K; Geom::CubicBezier const *cubic_1 = dynamic_cast(&*knot_curve_1); - Ray ray_1(start_arc_point, curve_it1->finalPoint()); + Geom::Ray ray_1(start_arc_point, curve_it1->finalPoint()); if (cubic_1) { ray_1.setPoints((*cubic_1)[2], start_arc_point); } - Point handle_1 = Point::polar(ray_1.angle(), k1) + start_arc_point; + Geom::Point handle_1 = Geom::Point::polar(ray_1.angle(), k1) + start_arc_point; if (time0 == 1) { handle_1 = start_arc_point; } - Curve *knot_curve_2 = curve_it2_fixed->portion(times[2], 1); + Geom::Curve *knot_curve_2 = curve_it2_fixed->portion(times[2], 1); Geom::CubicBezier const *cubic_2 = dynamic_cast(&*knot_curve_2); - Ray ray_2(curve_it2_fixed->initialPoint(), end_arc_point); + Geom::Ray ray_2(curve_it2_fixed->initialPoint(), end_arc_point); if (cubic_2) { ray_2.setPoints(end_arc_point, (*cubic_2)[1]); } - Point handle_2 = end_arc_point - Point::polar(ray_2.angle(), k2); + Geom::Point handle_2 = end_arc_point - Geom::Point::polar(ray_2.angle(), k2); bool ccw_toggle = cross(curve_it1->finalPoint() - start_arc_point, end_arc_point - start_arc_point) < 0; @@ -610,7 +603,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (ccw_toggle) { handleAngle = ray_1.angle() + angle; } - Point inverse_handle_1 = Point::polar(handleAngle, k1) + start_arc_point; + Geom::Point inverse_handle_1 = Geom::Point::polar(handleAngle, k1) + start_arc_point; if (time0 == 1) { inverse_handle_1 = start_arc_point; } @@ -618,39 +611,40 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (ccw_toggle) { handleAngle = ray_2.angle() - angle; } - Point inverse_handle_2 = end_arc_point - Point::polar(handleAngle, k2); + Geom::Point inverse_handle_2 = end_arc_point - Geom::Point::polar(handleAngle, k2); if (times[2] == 1) { end_arc_point = curve_it2_fixed->pointAt(times[2]); } if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0]); } - Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); - Line const angled_line(start_arc_point, end_arc_point); + Geom::Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); + Geom::Line const angled_line(start_arc_point, end_arc_point); double arc_angle = Geom::angle_between(x_line, angled_line); double radius = Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)) / sin(angle / 2.0); - Coord rx = radius; - Coord ry = rx; + Geom::Coord rx = radius; + Geom::Coord ry = rx; if (times[1] != 1) { if (times[1] != times[0] || times[1] == times[0] == 1) { if (!knot_curve_1->isDegenerate()) { tmp_path.append(*knot_curve_1); } } - SatelliteType type = satellite.satelliteType; + SatelliteType type = satellite.satellite_type; size_t steps = satellite.steps; if (steps < 1) { steps = 1; } - if (type == C) { + if (type == CHAMFER) { Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { - path_chamfer.appendNew(rx, ry, arc_angle, 0, + method == FM_ARC) + { + path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { path_chamfer.appendNew(handle_1, handle_2, @@ -658,19 +652,19 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } double chamfer_stepsTime = 1.0 / steps; for (size_t i = 1; i < steps; i++) { - Geom::Point chamfer_step = - path_chamfer.pointAt(chamfer_stepsTime * i); + Geom::Point chamfer_step = path_chamfer.pointAt(chamfer_stepsTime * i); tmp_path.appendNew(chamfer_step); } tmp_path.appendNew(end_arc_point); - } else if (type == IC) { + } else if (type == INVERSE_CHAMFER) { Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { + method == FM_ARC) + { ccw_toggle = ccw_toggle ? 0 : 1; - path_chamfer.appendNew(rx, ry, arc_angle, 0, + path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { path_chamfer.appendNew( @@ -683,22 +677,24 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) tmp_path.appendNew(chamfer_step); } tmp_path.appendNew(end_arc_point); - } else if (type == IF) { + } else if (type == INVERSE_FILLET) { if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { + method == FM_ARC) + { ccw_toggle = ccw_toggle ? 0 : 1; - tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { tmp_path.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); } - } else if (type == F) { + } else if (type == FILLET) { if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { - tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, + method == FM_ARC) + { + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { tmp_path.appendNew(handle_1, handle_2, diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 48056924a..bab278cf5 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -7,11 +7,7 @@ * * Copyright (C) 2014 Author(s) * - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours + * Jabiertxof:Thanks to all people help me * * Released under GNU GPL, read the file 'COPYING' for more information */ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index c71b8ed55..9b326fe32 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -83,7 +83,14 @@ ArrayParam::readsvg(const gchar * str) if (sp_svg_satellite_read_d(str, &sat)) { return sat; } - Satellite satellite(Geom::F, true, false, false, true, 0.0, 0.0, 0); + Satellite satellite(FILLET); + satellite.setIsTime(true); + satellite.setActive(false); + satellite.setHasMirror(false); + satellite.setHidden(true); + satellite.setAmount(0.0); + satellite.setAngle(0.0); + satellite.setSteps(0); return satellite; } diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 5a90d1930..7df849c24 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -1,10 +1,8 @@ /* - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours + * Author(s): + * Jabiertxo Arraiza Cenoz + * + * Copyright (C) 2014 Author(s) * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -19,8 +17,6 @@ // this has to be included last. #include -using namespace Geom; - namespace Inkscape { namespace LivePathEffect { @@ -88,7 +84,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) if (!_vector[i].active || _vector[i].hidden) { continue; } - if ((!_vector[i].hasMirror && mirror == true) || _vector[i].amount == 0) { + if ((!_vector[i].has_mirror && mirror == true) || _vector[i].amount == 0) { continue; } double pos = 0; @@ -97,7 +93,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } Geom::D2 d2 = pwd2[i]; bool overflow = false; - double size_out = _vector[i].size(pwd2[i]); + double size_out = _vector[i].arcDistance(pwd2[i]); double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); double lenght_in = 0; boost::optional d2_prev_index = path_info.previous(i); @@ -133,9 +129,9 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) Geom::Affine aff = Geom::Affine(); aff *= Geom::Scale(_helper_size); if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(90)); + aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(90)); } else { - aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(270)); + aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } pathv *= aff; pathv += d2.valueAt(pos); @@ -161,9 +157,9 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) aff = Geom::Affine(); aff *= Geom::Scale(_helper_size / 2.0); if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(90)); + aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(90)); } else { - aff *= Geom::Rotate(ray_1.angle() - deg_to_rad(270)); + aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } pathv *= aff; pathv += d2.valueAt(pos); @@ -193,7 +189,7 @@ void SatelliteArrayParam::param_transform_multiply(Geom::Affine const &postmul, if (prefs->getBool("/options/transform/rectcorners", true)) { for (size_t i = 0; i < _vector.size(); ++i) { - if (!_vector[i].isTime && _vector[i].amount > 0) { + if (!_vector[i].is_time && _vector[i].amount > 0) { _vector[i].amount = _vector[i].amount * ((postmul.expansionX() + postmul.expansionY()) / 2); } @@ -214,23 +210,23 @@ void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, if (!_vector[i].active) { continue; } - if (!_vector[i].hasMirror && mirror == true) { + if (!_vector[i].has_mirror && mirror == true) { continue; } using namespace Geom; - SatelliteType type = _vector[i].satelliteType; + SatelliteType type = _vector[i].satellite_type; //IF is for filletChamfer effect... if (_effectType == FILLET_CHAMFER) { const gchar *tip; - if (type == C) { + if (type == CHAMFER) { tip = _("Chamfer: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); - } else if (type == IC) { + } else if (type == INVERSE_CHAMFER) { tip = _("Inverse Chamfer: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); - } else if (type == IF) { + } else if (type == INVERSE_FILLET) { tip = _("Inverse Fillet: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); @@ -263,8 +259,8 @@ FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( SatelliteArrayParam *p, size_t index) : _pparam(p), _index(index) {} -void FilletChamferKnotHolderEntity::knot_set(Point const &p, - Point const &/*origin*/, +void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, + Geom::Point const &/*origin*/, guint state) { Geom::Point s = snap_knot_position(p, state); @@ -298,10 +294,10 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, if (time_start > mirror_time) { mirror_time = time_start; } - double size = satellite.arcLengthAt(mirror_time, d2_in); + double size = arcLengthAt(mirror_time, d2_in); double amount = Geom::length(d2_in, Geom::EPSILON) - size; - if (satellite.isTime) { - amount = satellite.timeAtArcLength(amount, pwd2[index]); + if (satellite.is_time) { + amount = timeAtArcLength(amount, pwd2[index]); } satellite.amount = amount; } @@ -323,20 +319,20 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const index = _index - _pparam->_vector.size(); } if (!valid_index(index)) { - return Point(infinity(), infinity()); + return Geom::Point(Geom::infinity(), Geom::infinity()); } Satellite satellite = _pparam->_vector.at(index); if (!_pparam->_last_pointwise) { - return Point(infinity(), infinity()); + return Geom::Point(Geom::infinity(), Geom::infinity()); } if (!satellite.active || satellite.hidden) { - return Point(infinity(), infinity()); + return Geom::Point(Geom::infinity(), Geom::infinity()); } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); Pathinfo path_info(pwd2); if (pwd2.size() <= index) { - return Point(infinity(), infinity()); + return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); if (_index >= _pparam->_vector.size()) { @@ -344,7 +340,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const boost::optional d2_prev_index = path_info.previous(index); if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; - double s = satellite.size(pwd2[index]); + double s = satellite.arcDistance(pwd2[index]); double t = satellite.time(s, true, d2_in); if (t > 1) { t = 1; @@ -383,34 +379,34 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); } else { using namespace Geom; - SatelliteType type = _pparam->_vector.at(index).satelliteType; + SatelliteType type = _pparam->_vector.at(index).satellite_type; switch (type) { - case F: - type = IF; + case FILLET: + type = INVERSE_FILLET; break; - case IF: - type = C; + case INVERSE_FILLET: + type = CHAMFER; break; - case C: - type = IC; + case CHAMFER: + type = INVERSE_CHAMFER; break; default: - type = F; + type = FILLET; break; } - _pparam->_vector.at(index).satelliteType = type; + _pparam->_vector.at(index).satellite_type = type; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); const gchar *tip; - if (type == C) { + if (type == CHAMFER) { tip = _("Chamfer: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); - } else if (type == IC) { + } else if (type == INVERSE_CHAMFER) { tip = _("Inverse Chamfer: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); - } else if (type == IF) { + } else if (type == INVERSE_FILLET) { tip = _("Inverse Fillet: Ctrl+Click toggle type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); @@ -423,10 +419,10 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); + Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); Pathinfo path_info(pwd2); double amount = _pparam->_vector.at(index).amount; - if (!_pparam->_use_distance && !_pparam->_vector.at(index).isTime) { + if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { boost::optional prev = path_info.previous(index); if (prev) { amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*prev], pwd2[index],_pparam->_vector.at(*prev)); @@ -435,7 +431,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } bool aprox = false; - D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; + Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; boost::optional d2_prev_index = path_info.previous(index); if (d2_prev_index) { Geom::D2 d2_in = @@ -464,8 +460,8 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) } double amount = satellite.amount; double max_amount = amount; - if (!_pparam->_use_distance && !satellite.isTime) { - Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); + if (!_pparam->_use_distance && !satellite.is_time) { + Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); Pathinfo path_info(pwd2); boost::optional prev = path_info.previous(index); if (prev) { diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index 2b49d1952..f89668a4c 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; -- cgit v1.2.3 From 63b289b4a3341f435e49dde40503636ba7b01b6a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 21:27:46 +0200 Subject: 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(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index 5ffd1d31e..d37b8b6da 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 8a6c51e51..cd3a3b2b8 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 b1f2235c6..3cb4ff136 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 c2d4ef715..d03839875 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, -- cgit v1.2.3 From c7925bda67f038dd5054329c43936658ca2cae76 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 10 May 2015 22:36:27 +0200 Subject: some comments and pointwise related refactor (bzr r13645.1.91) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp index d37b8b6da..d73f8f707 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 cd3a3b2b8..41753c68f 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 3041c60ea..5f6c0d29e 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 3cb4ff136..d83b54b79 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 d03839875..cd3f65f68 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 16bef6a99..3e7c1d0e1 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -139,8 +139,11 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) global_counter++; } } - pointwise = new Pointwise(pwd2_in, satellites); + pointwise = new Pointwise(); + pointwise->setPwd2(pwd2_in); + pointwise->setSatellites(satellites); pointwise->setPathInfo(original_pathv); + pointwise->setStart(); satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -278,12 +281,13 @@ void LPEFilletChamfer::updateAmount() } std::vector satellites = pointwise->getSatellites(); Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo path_info(pwd2); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if (!path_info.closed(it - satellites.begin()) && - path_info.first(it - satellites.begin()) == + if (!path_info->closed(it - satellites.begin()) && + path_info->first(it - satellites.begin()) == (unsigned)(it - satellites.begin())) { it->amount = 0; @@ -293,7 +297,7 @@ void LPEFilletChamfer::updateAmount() continue; } boost::optional previous = - path_info.previous(it - satellites.begin()); + path_info->previous(it - satellites.begin()); if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { @@ -421,8 +425,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) it->hidden = hide_knots; ++it; } - Pathinfo path_info(original_pathv); - size_t number_curves = path_info.size(); + Pathinfo* path_info = new Pathinfo(); + path_info->set(original_pathv); + size_t number_curves = path_info->size(); + //if are diferent sizes call to poinwise recalculate if (pointwise && number_curves != sats.size()) { Satellite sat(sats[0].satellite_type); sat.setIsTime(sats[0].is_time); @@ -434,9 +440,12 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) sat.setSteps(0); pointwise->recalculateForNewPwd2(pwd2_in, original_pathv, sat); } else { - pointwise = new Pointwise(pwd2_in, sats); + pointwise = new Pointwise(); + pointwise->setPwd2(pwd2_in); + pointwise->setSatellites(sats); } pointwise->setPathInfo(original_pathv); + pointwise->setStart(); satellites_param.setPointwise(pointwise); refreshKnots(); } else { diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 7df849c24..4eefea0b0 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -76,7 +76,8 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) return; } Geom::Piecewise > pwd2 = _last_pointwise->getPwd2(); - Pathinfo path_info(pwd2); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); if (mirror == true) { _hp.clear(); } @@ -96,7 +97,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i].arcDistance(pwd2[i]); double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); double lenght_in = 0; - boost::optional d2_prev_index = path_info.previous(i); + boost::optional d2_prev_index = path_info->previous(i); if (d2_prev_index) { lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); } @@ -282,9 +283,10 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo path_info(pwd2); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); if (_pparam->_vector.size() <= _index) { - boost::optional d2_prev_index = path_info.previous(index); + boost::optional d2_prev_index = path_info->previous(index); if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; double mirror_time = Geom::nearest_point(s, d2_in); @@ -330,14 +332,15 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo path_info(pwd2); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); if (pwd2.size() <= index) { return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); if (_index >= _pparam->_vector.size()) { tmp_point = satellite.getPosition(pwd2[index]); - boost::optional d2_prev_index = path_info.previous(index); + boost::optional d2_prev_index = path_info->previous(index); if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; double s = satellite.arcDistance(pwd2[index]); @@ -420,10 +423,11 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } else if (state & GDK_SHIFT_MASK) { Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Pathinfo path_info(pwd2); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); double amount = _pparam->_vector.at(index).amount; if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { - boost::optional prev = path_info.previous(index); + boost::optional prev = path_info->previous(index); if (prev) { amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*prev], pwd2[index],_pparam->_vector.at(*prev)); } else { @@ -432,7 +436,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } bool aprox = false; Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; - boost::optional d2_prev_index = path_info.previous(index); + boost::optional d2_prev_index = path_info->previous(index); if (d2_prev_index) { Geom::D2 d2_in = _pparam->_last_pointwise->getPwd2()[*d2_prev_index]; @@ -462,8 +466,9 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Pathinfo path_info(pwd2); - boost::optional prev = path_info.previous(index); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); + boost::optional prev = path_info->previous(index); if (prev) { amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index], _pparam->_vector.at(*prev)); } else { -- cgit v1.2.3 From d11134922137f029c42919ed3298924135bec386 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 11 May 2015 00:24:25 +0200 Subject: fix a minor bug calculating max time (bzr r13645.1.92) --- src/helper/geom-satellite.cpp | 2 +- src/live_effects/lpe-fillet-chamfer.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index cd3f65f68..eed9706cf 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 3e7c1d0e1..cc21d99cc 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -565,6 +565,9 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (time1 <= time0) { time1 = time0; } + if (time2 > 1) { + time2 = 1; + } std::vector times; times.push_back(time0); times.push_back(time1); @@ -632,7 +635,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double arc_angle = Geom::angle_between(x_line, angled_line); double radius = Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)) / - sin(angle / 2.0); + sin(angle / 2.0); Geom::Coord rx = radius; Geom::Coord ry = rx; if (times[1] != 1) { -- cgit v1.2.3 From d6710f8318ba6f95e9dd5ad96d341acc41b14a4e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 25 Jun 2015 19:54:53 +0200 Subject: 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(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 5f6c0d29e..dc95ffda4 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 d83b54b79..79504ecff 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); -- cgit v1.2.3 From a5d2901e1f17879bc65e23b3ff26f8c304658ce4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 26 Jun 2015 17:58:32 +0200 Subject: removed reverse path, commented why (bzr r13645.1.97) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index dc95ffda4..5f6c0d29e 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 79504ecff..d83b54b79 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 cc21d99cc..eaf1c6a08 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -429,6 +429,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) path_info->set(original_pathv); size_t number_curves = path_info->size(); //if are diferent sizes call to poinwise recalculate + //TODO: fire a reverse satellites on reverse path. Maybe a new method + //like "are_similar" to avoid precission issues on reverse a pointwise + // and after convert to Pathvector if (pointwise && number_curves != sats.size()) { Satellite sat(sats[0].satellite_type); sat.setIsTime(sats[0].is_time); -- cgit v1.2.3 From 57b065b5ffb5a871b5efac52f03cb95355bfa119 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 5 Jul 2015 02:57:00 +0200 Subject: fix to compile on Krzysztof merge previous to fix the improvements in the merge request (bzr r13645.1.100) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 5f6c0d29e..6910207bf 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 eed9706cf..f5f28544d 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 722adbef4..42c5687bd 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 a0aada090..b617c929e 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -4,13 +4,6 @@ * * Copyright (C) 2014 Author(s) * - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * Also to Mc- (IRC nick) for his important contribution to find real time - * values based on - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -20,15 +13,13 @@ #include "display/curve.h" #include "helper/geom-curves.h" #include "helper/geom-satellite.h" -#include "helper/geom-satellite-enum.h" #include "helper/geom-pathinfo.h" -#include <2geom/svg-elliptical-arc.h> +#include <2geom/elliptical-arc.h> #include "knotholder.h" #include // TODO due to internal breakage in glibmm headers, this must be last: #include -using namespace Geom; namespace Inkscape { namespace LivePathEffect { @@ -41,13 +32,12 @@ static const Util::EnumDataConverter FMConverter(FilletMethodData, LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellitearrayparam_values(_("pair_array_param"), _("pair_array_param"), - "satellitearrayparam_values", &wr, this), - unit(_("Unit:"), _("Unit"), "unit", &wr, this), + satellites_param(_("pair_array_param"), _("pair_array_param"), + "satellites_param", &wr, this), method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, - this, 0.), + this, 0.0), chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 1), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), @@ -66,10 +56,9 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise(NULL), segment_size(0) + pointwise(NULL) { - registerParameter(&satellitearrayparam_values); - registerParameter(&unit); + registerParameter(&satellites_param); registerParameter(&method); registerParameter(&radius); registerParameter(&chamfer_steps); @@ -81,7 +70,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) registerParameter(&only_selected); registerParameter(&hide_knots); - radius.param_set_range(0., infinity()); + radius.param_set_range(0.0, Geom::infinity()); radius.param_set_increments(1, 1); radius.param_set_digits(4); chamfer_steps.param_set_range(1, 999); @@ -99,13 +88,13 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { - PathVector const &original_pathv = + Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); + Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int global_counter = 0; - std::vector satellites; - for (PathVector::const_iterator path_it = original_pathv.begin(); + std::vector satellites; + for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) { continue; @@ -113,7 +102,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->closed()) { - const Curve &closingline = path_it->back_closed(); + Geom::Curve const &closingline = path_it->back_closed(); // the closing line segment is always of type // LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { @@ -129,12 +118,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()) { - g_warning("LPE Fillet not handle degenerate curves."); - SPLPEItem *item = const_cast(lpeItem); - item->removeCurrentPathEffect(false); - return; - } bool active = true; bool hidden = false; if (counter == 0) { @@ -142,16 +125,26 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, active, mirror_knots, hidden, 0.0, 0.0, - steps); + Satellite satellite(FILLET); + satellite.setIsTime(flexible); + satellite.setActive(active); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hidden); + satellite.setAmount(0.0); + satellite.setAngle(0.0); + satellite.setSteps(steps); satellites.push_back(satellite); ++curve_it1; counter++; global_counter++; } } - pointwise = new Pointwise(pwd2_in, satellites); - satellitearrayparam_values.setPointwise(pointwise); + pointwise = new Pointwise(); + pointwise->setPwd2(pwd2_in); + pointwise->setSatellites(satellites); + pointwise->setPathInfo(original_pathv); + pointwise->setStart(); + satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem *item = const_cast(lpeItem); @@ -176,13 +169,12 @@ Gtk::Widget *LPEFilletChamfer::newWidget() if (param->param_key == "radius") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); - widg_registered->signal_value_changed() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); + widg_registered->signal_value_changed().connect( + sigc::mem_fun(*this, &LPEFilletChamfer::updateAmount)); widg = widg_registered; if (widg) { Gtk::HBox *scalar_parameter = dynamic_cast(widg); - std::vector childList = - scalar_parameter->get_children(); + std::vector childList = scalar_parameter->get_children(); Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(6); } @@ -194,16 +186,15 @@ Gtk::Widget *LPEFilletChamfer::newWidget() widg = widg_registered; if (widg) { Gtk::HBox *scalar_parameter = dynamic_cast(widg); - std::vector childList = - scalar_parameter->get_children(); + std::vector childList = scalar_parameter->get_children(); Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(3); } } else if (param->param_key == "helper_size") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); - widg_registered->signal_value_changed() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); + widg_registered->signal_value_changed().connect( + sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); } else if (param->param_key == "only_selected") { Gtk::manage(widg); } @@ -255,28 +246,28 @@ Gtk::Widget *LPEFilletChamfer::newWidget() void LPEFilletChamfer::fillet() { - updateSatelliteType(F); + updateSatelliteType(FILLET); } void LPEFilletChamfer::inverseFillet() { - updateSatelliteType(IF); + updateSatelliteType(INVERSE_FILLET); } void LPEFilletChamfer::chamfer() { - updateSatelliteType(C); + updateSatelliteType(CHAMFER); } void LPEFilletChamfer::inverseChamfer() { - updateSatelliteType(IC); + updateSatelliteType(INVERSE_CHAMFER); } void LPEFilletChamfer::refreshKnots() { - if (satellitearrayparam_values.knoth) { - satellitearrayparam_values.knoth->update_knots(); + if (satellites_param.knoth) { + satellites_param.knoth->update_knots(); } } @@ -284,19 +275,21 @@ void LPEFilletChamfer::updateAmount() { double power = 0; if (!flexible) { - power = Inkscape::Util::Quantity::convert(radius, unit.get_abbreviation(), - defaultUnit); + power = radius; } else { power = radius / 100; } - std::vector satellites = pointwise->getSatellites(); - Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo path_info(pwd2); - for (std::vector::iterator it = satellites.begin(); - it != satellites.end(); ++it) { - if (!path_info.isClosed(it - satellites.begin()) && - path_info.first(it - satellites.begin()) == - (unsigned)(it - satellites.begin())) { + std::vector satellites = pointwise->getSatellites(); + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + Pathinfo* path_info = new Pathinfo(); + path_info->set(pwd2); + for (std::vector::iterator it = satellites.begin(); + it != satellites.end(); ++it) + { + if (!path_info->closed(it - satellites.begin()) && + path_info->first(it - satellites.begin()) == + (unsigned)(it - satellites.begin())) + { it->amount = 0; continue; } @@ -304,41 +297,43 @@ void LPEFilletChamfer::updateAmount() continue; } boost::optional previous = - path_info.previous(it - satellites.begin()); - boost::optional > previous_d2 = boost::none; - boost::optional previous_satellite = boost::none; - if (previous) { - previous_d2 = pwd2[*previous]; - previous_satellite = satellites[*previous]; - } + path_info->previous(it - satellites.begin()); if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { if (!use_knot_distance && !flexible) { - it->amount = it->radToLen(power, previous_d2, - pwd2[it - satellites.begin()], previous_satellite); + if(previous){ + it->amount = it->radToLen(power, pwd2[*previous], + pwd2[it - satellites.begin()]); + } else { + it->amount = 0.0; + } } else { it->amount = power; } } } else { if (!use_knot_distance && !flexible) { - it->amount = it->radToLen(power, previous_d2, - pwd2[it - satellites.begin()], previous_satellite); + if(previous){ + it->amount = it->radToLen(power, pwd2[*previous], + pwd2[it - satellites.begin()]); + } else { + it->amount = 0.0; + } } else { it->amount = power; } } } pointwise->setSatellites(satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() { - std::vector satellites = pointwise->getSatellites(); - Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); + std::vector satellites = pointwise->getSatellites(); + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (ignore_radius_0 && it->amount == 0) { continue; @@ -353,14 +348,14 @@ void LPEFilletChamfer::updateChamferSteps() } } pointwise->setSatellites(satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } -void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) +void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - std::vector satellites = pointwise->getSatellites(); - Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); + std::vector satellites = pointwise->getSatellites(); + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { if (ignore_radius_0 && it->amount == 0) { continue; @@ -368,18 +363,21 @@ void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { - it->satelliteType = satellitetype; + it->satellite_type = satellitetype; } } else { - it->satelliteType = satellitetype; + it->satellite_type = satellitetype; } } pointwise->setSatellites(satellites); - satellitearrayparam_values.setPointwise(pointwise); + satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { + if(!_hp.empty()){ + _hp.clear(); + } SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { @@ -389,93 +387,96 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } //fillet chamfer specific calls - satellitearrayparam_values.setDocumentUnit(defaultUnit); - satellitearrayparam_values.setUseDistance(use_knot_distance); - satellitearrayparam_values.setUnit(unit.get_abbreviation()); + satellites_param.setUseDistance(use_knot_distance); //mandatory call - satellitearrayparam_values.setEffectType(effectType()); + satellites_param.setEffectType(effectType()); - PathVector const &original_pathv = + Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Piecewise > pwd2_in = paths_to_pw(original_pathv); + Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector sats = satellitearrayparam_values.data(); - //optional call + std::vector sats = satellites_param.data(); + if(sats.empty()){ + doOnApply(lpeItem); + sats = satellites_param.data(); + } if (hide_knots) { - satellitearrayparam_values.setHelperSize(0); + satellites_param.setHelperSize(0); } else { - satellitearrayparam_values.setHelperSize(helper_size); + satellites_param.setHelperSize(helper_size); } - bool refresh = false; - bool hide = true; for (std::vector::iterator it = sats.begin(); it != sats.end();) { - if (it->isTime != flexible) { - it->isTime = flexible; + if (it->is_time != flexible) { + it->is_time = flexible; double amount = it->amount; - D2 d2_in = pwd2_in[it - sats.begin()]; - if (it->isTime) { - double time = it->toTime(amount, d2_in); + Geom::D2 d2_in = pwd2_in[it - sats.begin()]; + if (it->is_time) { + double time = timeAtArcLength(amount, d2_in); it->amount = time; } else { - double size = it->toSize(amount, d2_in); + double size = arcLengthAt(amount, d2_in); it->amount = size; } } - if (it->hasMirror != mirror_knots) { - it->hasMirror = mirror_knots; - refresh = true; - } - if (it->hidden == false) { - hide = false; + if (it->has_mirror != mirror_knots) { + it->has_mirror = mirror_knots; } it->hidden = hide_knots; ++it; } - if (hide != hide_knots) { - refresh = true; - } - - if (pointwise && c->get_segment_count() != segment_size && segment_size != 0) { - pointwise->recalculateForNewPwd2(pwd2_in); - segment_size = c->get_segment_count(); + Pathinfo* path_info = new Pathinfo(); + path_info->set(original_pathv); + size_t number_curves = path_info->size(); + //if are diferent sizes call to poinwise recalculate + //TODO: fire a reverse satellites on reverse path. Maybe a new method + //like "are_similar" to avoid precission issues on reverse a pointwise + // and after convert to Pathvector + if (pointwise && number_curves != sats.size()) { + Satellite sat(sats[0].satellite_type); + sat.setIsTime(sats[0].is_time); + sat.setActive(true); + sat.setHasMirror( sats[0].has_mirror); + sat.setHidden(false); + sat.setAmount(0.0); + sat.setAngle(0.0); + sat.setSteps(0); + pointwise->recalculateForNewPwd2(pwd2_in, original_pathv, sat); } else { - pointwise = new Pointwise(pwd2_in, sats); - segment_size = c->get_segment_count(); - } - satellitearrayparam_values.setPointwise(pointwise); - if (refresh) { - refreshKnots(); + pointwise = new Pointwise(); + pointwise->setPwd2(pwd2_in); + pointwise->setSatellites(sats); } + pointwise->setPathInfo(original_pathv); + pointwise->setStart(); + satellites_param.setPointwise(pointwise); + refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } } void -LPEFilletChamfer::adjustForNewPath(std::vector const &path_in) +LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec) { - if (!path_in.empty() && pointwise) { - pointwise->recalculateForNewPwd2(remove_short_cuts( - paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)), 0.01)); - satellitearrayparam_values.setPointwise(pointwise); - } + hp_vec.push_back(_hp); } -std::vector -LPEFilletChamfer::doEffect_path(std::vector const &path_in) +Geom::PathVector +LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) { const double GAP_HELPER = 0.00001; - std::vector path_out; + Geom::PathVector path_out; size_t counter = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - std::vector path_in_processed = + Geom::PathVector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); - for (PathVector::const_iterator path_it = path_in_processed.begin(); + for (Geom::PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { if (path_it->empty()) { continue; } + _hp.push_back(*path_it); Geom::Path tmp_path; Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); @@ -502,14 +503,20 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) size_t counter_curves = 0; size_t first = counter; double time0 = 0; - std::vector sats = pointwise->getSatellites(); + std::vector sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { - if ((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()) { - g_warning("LPE Fillet not handle degenerate curves."); - return path_in; + if (curve_it2 != curve_endit && (*curve_it2).isDegenerate()) { + ++curve_it2; + } + if ((*curve_it1).isDegenerate()) { + ++curve_it1; + counter++; + counter_curves++; + time0 = 0.0; + continue; } Satellite satellite; - Curve *curve_it2_fixed = path_it->begin()->duplicate(); + Geom::Curve *curve_it2_fixed = path_it->begin()->duplicate(); if (!path_it->closed()) { if (curve_it2 != curve_endit) { curve_it2_fixed = (*curve_it2).duplicate(); @@ -518,7 +525,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } } else { if (time0 != 1) { - Curve *last_curve = curve_it1->portion(time0, 1); + Geom::Curve *last_curve = curve_it1->portion(time0, 1); last_curve->setInitial(tmp_path.finalPoint()); tmp_path.append(*last_curve); } @@ -550,7 +557,7 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } bool last = curve_it2 == curve_endit; - double s = satellite.size(curve_it2_fixed->toSBasis()); + double s = satellite.arcDistance(curve_it2_fixed->toSBasis()); double time1 = satellite.time(s, true, (*curve_it1).toSBasis()); double time2 = satellite.time(curve_it2_fixed->toSBasis()); if (!satellite.active) { @@ -561,19 +568,22 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (time1 <= time0) { time1 = time0; } + if (time2 > 1) { + time2 = 1; + } std::vector times; times.push_back(time0); times.push_back(time1); times.push_back(time2); - Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); + Geom::Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); if (counter_curves > 0) { knot_curve_1->setInitial(tmp_path.finalPoint()); } else { tmp_path.start((*curve_it1).pointAt(times[0])); } - Point start_arc_point = knot_curve_1->finalPoint(); - Point end_arc_point = curve_it2_fixed->pointAt(times[2]); + Geom::Point start_arc_point = knot_curve_1->finalPoint(); + Geom::Point end_arc_point = curve_it2_fixed->pointAt(times[2]); if (times[2] == 1) { end_arc_point = curve_it2_fixed->pointAt(times[2] - GAP_HELPER); } @@ -584,31 +594,31 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) double k2 = distance(end_arc_point, curve_it2_fixed->initialPoint()) * K; Geom::CubicBezier const *cubic_1 = dynamic_cast(&*knot_curve_1); - Ray ray_1(start_arc_point, curve_it1->finalPoint()); + Geom::Ray ray_1(start_arc_point, curve_it1->finalPoint()); if (cubic_1) { ray_1.setPoints((*cubic_1)[2], start_arc_point); } - Point handle_1 = Point::polar(ray_1.angle(), k1) + start_arc_point; + Geom::Point handle_1 = Geom::Point::polar(ray_1.angle(), k1) + start_arc_point; if (time0 == 1) { handle_1 = start_arc_point; } - Curve *knot_curve_2 = curve_it2_fixed->portion(times[2], 1); + Geom::Curve *knot_curve_2 = curve_it2_fixed->portion(times[2], 1); Geom::CubicBezier const *cubic_2 = dynamic_cast(&*knot_curve_2); - Ray ray_2(curve_it2_fixed->initialPoint(), end_arc_point); + Geom::Ray ray_2(curve_it2_fixed->initialPoint(), end_arc_point); if (cubic_2) { ray_2.setPoints(end_arc_point, (*cubic_2)[1]); } - Point handle_2 = end_arc_point - Point::polar(ray_2.angle(), k2); + Geom::Point handle_2 = end_arc_point - Geom::Point::polar(ray_2.angle(), k2); bool ccw_toggle = cross(curve_it1->finalPoint() - start_arc_point, - end_arc_point - start_arc_point) < 0; + end_arc_point - start_arc_point) < 0; double angle = angle_between(ray_1, ray_2, ccw_toggle); double handleAngle = ray_1.angle() - angle; if (ccw_toggle) { handleAngle = ray_1.angle() + angle; } - Point inverse_handle_1 = Point::polar(handleAngle, k1) + start_arc_point; + Geom::Point inverse_handle_1 = Geom::Point::polar(handleAngle, k1) + start_arc_point; if (time0 == 1) { inverse_handle_1 = start_arc_point; } @@ -616,39 +626,40 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) if (ccw_toggle) { handleAngle = ray_2.angle() - angle; } - Point inverse_handle_2 = end_arc_point - Point::polar(handleAngle, k2); + Geom::Point inverse_handle_2 = end_arc_point - Geom::Point::polar(handleAngle, k2); if (times[2] == 1) { end_arc_point = curve_it2_fixed->pointAt(times[2]); } if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0]); } - Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); - Line const angled_line(start_arc_point, end_arc_point); + Geom::Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); + Geom::Line const angled_line(start_arc_point, end_arc_point); double arc_angle = Geom::angle_between(x_line, angled_line); double radius = Geom::distance(start_arc_point, - middle_point(start_arc_point, end_arc_point)) / - sin(angle / 2.0); - Coord rx = radius; - Coord ry = rx; + middle_point(start_arc_point, end_arc_point)) / + sin(angle / 2.0); + Geom::Coord rx = radius; + Geom::Coord ry = rx; if (times[1] != 1) { if (times[1] != times[0] || times[1] == times[0] == 1) { if (!knot_curve_1->isDegenerate()) { tmp_path.append(*knot_curve_1); } } - SatelliteType type = satellite.satelliteType; + SatelliteType type = satellite.satellite_type; size_t steps = satellite.steps; if (steps < 1) { steps = 1; } - if (type == C) { + if (type == CHAMFER) { Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { - path_chamfer.appendNew(rx, ry, arc_angle, 0, + method == FM_ARC) + { + path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { path_chamfer.appendNew(handle_1, handle_2, @@ -656,19 +667,19 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) } double chamfer_stepsTime = 1.0 / steps; for (size_t i = 1; i < steps; i++) { - Geom::Point chamfer_step = - path_chamfer.pointAt(chamfer_stepsTime * i); + Geom::Point chamfer_step = path_chamfer.pointAt(chamfer_stepsTime * i); tmp_path.appendNew(chamfer_step); } tmp_path.appendNew(end_arc_point); - } else if (type == IC) { + } else if (type == INVERSE_CHAMFER) { Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { + method == FM_ARC) + { ccw_toggle = ccw_toggle ? 0 : 1; - path_chamfer.appendNew(rx, ry, arc_angle, 0, + path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { path_chamfer.appendNew( @@ -681,22 +692,24 @@ LPEFilletChamfer::doEffect_path(std::vector const &path_in) tmp_path.appendNew(chamfer_step); } tmp_path.appendNew(end_arc_point); - } else if (type == IF) { + } else if (type == INVERSE_FILLET) { if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { + method == FM_ARC) + { ccw_toggle = ccw_toggle ? 0 : 1; - tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { tmp_path.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); } - } else if (type == F) { + } else if (type == FILLET) { if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) { - tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, + method == FM_ARC) + { + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { tmp_path.appendNew(handle_1, handle_2, diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index ed76eb0e6..d7549d070 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -7,17 +7,12 @@ * * Copyright (C) 2014 Author(s) * - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours + * Jabiertxof:Thanks to all people help me * * Released under GNU GPL, read the file 'COPYING' for more information */ #include "live_effects/parameter/enum.h" -#include "live_effects/parameter/unit.h" #include "live_effects/parameter/satellitearray.h" #include "live_effects/effect.h" #include "helper/geom-pointwise.h" @@ -26,52 +21,50 @@ namespace Inkscape { namespace LivePathEffect { enum FilletMethod { - FM_AUTO, - FM_ARC, - FM_BEZIER, - FM_END + FM_AUTO, + FM_ARC, + FM_BEZIER, + FM_END }; class LPEFilletChamfer : public Effect { public: - LPEFilletChamfer(LivePathEffectObject *lpeobject); - virtual ~LPEFilletChamfer(); - virtual void doBeforeEffect(SPLPEItem const *lpeItem); - virtual std::vector - doEffect_path(std::vector const &path_in); - virtual void doOnApply(SPLPEItem const *lpeItem); - virtual void adjustForNewPath(std::vector const &path_in); - virtual Gtk::Widget *newWidget(); + LPEFilletChamfer(LivePathEffectObject *lpeobject); + virtual ~LPEFilletChamfer(); + virtual void doBeforeEffect(SPLPEItem const *lpeItem); + virtual Geom::PathVector + doEffect_path(Geom::PathVector const &path_in); + virtual void doOnApply(SPLPEItem const *lpeItem); + virtual Gtk::Widget *newWidget(); + void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); + void updateSatelliteType(SatelliteType satellitetype); + void updateChamferSteps(); + void updateAmount(); + void refreshKnots(); + void chamfer(); + void inverseChamfer(); + void fillet(); + void inverseFillet(); - void updateSatelliteType(Geom::SatelliteType satellitetype); - void updateChamferSteps(); - void updateAmount(); - void refreshKnots(); - void chamfer(); - void inverseChamfer(); - void fillet(); - void inverseFillet(); - - SatelliteArrayParam satellitearrayparam_values; + SatelliteArrayParam satellites_param; private: - UnitParam unit; - EnumParam method; - ScalarParam radius; - ScalarParam chamfer_steps; - BoolParam flexible; - BoolParam mirror_knots; - BoolParam only_selected; - BoolParam use_knot_distance; - BoolParam hide_knots; - BoolParam ignore_radius_0; - ScalarParam helper_size; + EnumParam method; + ScalarParam radius; + ScalarParam chamfer_steps; + BoolParam flexible; + BoolParam mirror_knots; + BoolParam only_selected; + BoolParam use_knot_distance; + BoolParam hide_knots; + BoolParam ignore_radius_0; + ScalarParam helper_size; - Geom::Pointwise *pointwise; - double segCount; + Pointwise *pointwise; + Geom::PathVector _hp; - LPEFilletChamfer(const LPEFilletChamfer &); - LPEFilletChamfer &operator=(const LPEFilletChamfer &); + LPEFilletChamfer(const LPEFilletChamfer &); + LPEFilletChamfer &operator=(const LPEFilletChamfer &); }; diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 4eefea0b0..46c7396d0 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -134,8 +134,8 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } else { aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } + aff *= Geom::Translate(d2.valueAt(pos)); pathv *= aff; - pathv += d2.valueAt(pos); _hp.push_back(pathv[0]); _hp.push_back(pathv[1]); if (overflow) { @@ -146,8 +146,10 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 " "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; Geom::PathVector pathv = sp_svg_read_pathv(svgd); - pathv *= Geom::Scale(diameter); - pathv += point_a - Geom::Point(diameter * 0.35, diameter * 0.35); + aff = Geom::Affine(); + aff *= Geom::Scale(diameter); + aff *= Geom::Translate(point_a - Geom::Point(diameter * 0.35, diameter * 0.35)); + pathv *= aff; _hp.push_back(pathv[0]); } else { char const *svgd; @@ -162,8 +164,8 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } else { aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } + aff *= Geom::Translate(d2.valueAt(pos)); pathv *= aff; - pathv += d2.valueAt(pos); _hp.push_back(pathv[0]); } } @@ -289,7 +291,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, boost::optional d2_prev_index = path_info->previous(index); if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; - double mirror_time = Geom::nearest_point(s, d2_in); + double mirror_time = Geom::nearest_time(s, d2_in); double time_start = 0; std::vector sats = pointwise->getSatellites(); time_start = sats[*d2_prev_index].time(d2_in); @@ -470,7 +472,7 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) path_info->set(pwd2); boost::optional prev = path_info->previous(index); if (prev) { - amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index], _pparam->_vector.at(*prev)); + amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index]); } else { amount = 0.0; } -- cgit v1.2.3 From ebcbadbe16fe20e54a5daf9c5e6954521113d9cc Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 5 Jul 2015 03:14:24 +0200 Subject: Fix a bug displaying arcs (bzr r13645.1.101) --- src/live_effects/lpe-fillet-chamfer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index b617c929e..eb9f82918 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -659,6 +659,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || method == FM_ARC) { + ccw_toggle = ccw_toggle ? 0 : 1; path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { @@ -678,7 +679,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || method == FM_ARC) { - ccw_toggle = ccw_toggle ? 0 : 1; path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { @@ -697,7 +697,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || method == FM_ARC) { - ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { @@ -709,6 +708,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || method == FM_ARC) { + ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { -- cgit v1.2.3 From 936f6512b26120b882a1c68e50968a15002f3af4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Jul 2015 12:01:17 +0200 Subject: Fixes from branch review (bzr r13645.1.102) --- src/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 (limited to 'src') diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt index ff4760c24..aa99934b6 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 919234b47..54588d0ce 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 d73f8f707..000000000 --- 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 41753c68f..000000000 --- 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 6910207bf..7627b5dc3 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 eb9f82918..7871ccc1e 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -13,7 +13,6 @@ #include "display/curve.h" #include "helper/geom-curves.h" #include "helper/geom-satellite.h" -#include "helper/geom-pathinfo.h" #include <2geom/elliptical-arc.h> #include "knotholder.h" #include @@ -81,8 +80,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) helper_size.param_set_digits(0); } -LPEFilletChamfer::~LPEFilletChamfer() {} - void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) { SPLPEItem *splpeitem = const_cast(lpeItem); @@ -101,20 +98,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed()) { - Geom::Curve const &closingline = path_it->back_closed(); - // the closing line segment is always of type - // LineSegment. - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - // closingline.isDegenerate() did not work, because it only checks for - // *exact* zero length, which goes wrong for relative coordinates and - // rounding errors... - // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); - } - } - Geom::Path::const_iterator curve_end = curve_endit; - --curve_end; int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { @@ -142,7 +125,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) pointwise = new Pointwise(); pointwise->setPwd2(pwd2_in); pointwise->setSatellites(satellites); - pointwise->setPathInfo(original_pathv); pointwise->setStart(); satellites_param.setPointwise(pointwise); } else { @@ -281,14 +263,13 @@ void LPEFilletChamfer::updateAmount() } std::vector satellites = pointwise->getSatellites(); Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if (!path_info->closed(it - satellites.begin()) && - path_info->first(it - satellites.begin()) == - (unsigned)(it - satellites.begin())) + Geom::Path sat_path = pathvector_before_effect.pathAt(it - satellites.begin()); + size_t sat_curve_time = Geom::nearest_time(pathvector_before_effect.curveAt(it - satellites.begin()).initialPoint() , pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (!sat_path.closed() && sat_curve_time == first) { it->amount = 0; continue; @@ -296,8 +277,13 @@ void LPEFilletChamfer::updateAmount() if (ignore_radius_0 && it->amount == 0) { continue; } - boost::optional previous = - path_info->previous(it - satellites.begin()); + boost::optional previous = boost::none; + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + previous = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + previous = sat_curve_time - 1; + } if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { @@ -425,13 +411,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) it->hidden = hide_knots; ++it; } - Pathinfo* path_info = new Pathinfo(); - path_info->set(original_pathv); - size_t number_curves = path_info->size(); + size_t number_curves = original_pathv.curveCount(); //if are diferent sizes call to poinwise recalculate - //TODO: fire a reverse satellites on reverse path. Maybe a new method + //todo: fire a reverse satellites on reverse path. Maybe a new method //like "are_similar" to avoid precission issues on reverse a pointwise - // and after convert to Pathvector + //and after convert to Pathvector if (pointwise && number_curves != sats.size()) { Satellite sat(sats[0].satellite_type); sat.setIsTime(sats[0].is_time); @@ -447,7 +431,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise->setPwd2(pwd2_in); pointwise->setSatellites(sats); } - pointwise->setPathInfo(original_pathv); pointwise->setStart(); satellites_param.setPointwise(pointwise); refreshKnots(); @@ -488,18 +471,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) path_out.push_back(tmp_path); continue; } - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); - // the closing line segment is always of type - // Geom::LineSegment. - if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - // closingline.isDegenerate() did not work, because it only checks for - // *exact* zero length, which goes wrong for relative coordinates and - // rounding errors... - // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); - } - } size_t counter_curves = 0; size_t first = counter; double time0 = 0; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index d7549d070..804709342 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -30,7 +30,6 @@ enum FilletMethod { class LPEFilletChamfer : public Effect { public: LPEFilletChamfer(LivePathEffectObject *lpeobject); - virtual ~LPEFilletChamfer(); virtual void doBeforeEffect(SPLPEItem const *lpeItem); virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 9b326fe32..0abcd4b9b 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -20,7 +20,7 @@ sp_svg_satellite_read_d(gchar const *str, Satellite *sat){ return 0; } gchar ** strarray = g_strsplit(str, ",", 8); - if(strarray[7] && !strarray[8]){ + if(strlen(str) > 0 && strarray[7] && !strarray[8]){ sat->setSatelliteType(g_strstrip(strarray[0])); sat->is_time = strncmp(strarray[1],"1",1) == 0; sat->active = strncmp(strarray[2],"1",1) == 0; diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 46c7396d0..b7d403a91 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -37,8 +37,6 @@ SatelliteArrayParam::SatelliteArrayParam(const Glib::ustring &label, _last_pointwise = NULL; } -SatelliteArrayParam::~SatelliteArrayParam() {} - void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) @@ -76,8 +74,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) return; } Geom::Piecewise > pwd2 = _last_pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (mirror == true) { _hp.clear(); } @@ -97,7 +94,17 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i].arcDistance(pwd2[i]); double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); double lenght_in = 0; - boost::optional d2_prev_index = path_info->previous(i); + + Geom::Path sat_path = pointwise_pv.pathAt(i); + boost::optional d2_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(i).initialPoint() , pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + d2_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + d2_prev_index = sat_curve_time - 1; + } if (d2_prev_index) { lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); } @@ -285,10 +292,18 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); - if (_pparam->_vector.size() <= _index) { - boost::optional d2_prev_index = path_info->previous(index); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + if (_index >= _pparam->_vector.size() ) { + Geom::Path sat_path = pointwise_pv.pathAt(index); + boost::optional d2_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + d2_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + d2_prev_index = sat_curve_time - 1; + } if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; double mirror_time = Geom::nearest_time(s, d2_in); @@ -334,15 +349,23 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (pwd2.size() <= index) { return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); if (_index >= _pparam->_vector.size()) { tmp_point = satellite.getPosition(pwd2[index]); - boost::optional d2_prev_index = path_info->previous(index); + Geom::Path sat_path = pointwise_pv.pathAt(index); + boost::optional d2_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + d2_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + d2_prev_index = sat_curve_time - 1; + } if (d2_prev_index) { Geom::D2 d2_in = pwd2[*d2_prev_index]; double s = satellite.arcDistance(pwd2[index]); @@ -425,20 +448,28 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } else if (state & GDK_SHIFT_MASK) { Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); double amount = _pparam->_vector.at(index).amount; + Geom::Path sat_path = pointwise_pv.pathAt(index); + boost::optional d2_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + d2_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + d2_prev_index = sat_curve_time - 1; + } + if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { - boost::optional prev = path_info->previous(index); - if (prev) { - amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*prev], pwd2[index],_pparam->_vector.at(*prev)); + if (d2_prev_index) { + amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*d2_prev_index], pwd2[index],_pparam->_vector.at(*d2_prev_index)); } else { amount = 0.0; } } bool aprox = false; Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; - boost::optional d2_prev_index = path_info->previous(index); if (d2_prev_index) { Geom::D2 d2_in = _pparam->_last_pointwise->getPwd2()[*d2_prev_index]; @@ -468,9 +499,17 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Pathinfo* path_info = new Pathinfo(); - path_info->set(pwd2); - boost::optional prev = path_info->previous(index); + Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::Path sat_path = pointwise_pv.pathAt(index); + boost::optional prev = boost::none; + size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first){ + sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + prev = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first){ + prev = sat_curve_time - 1; + } if (prev) { amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index]); } else { diff --git a/src/live_effects/parameter/satellitearray.h b/src/live_effects/parameter/satellitearray.h index cc09e7589..bb8bf27c8 100644 --- a/src/live_effects/parameter/satellitearray.h +++ b/src/live_effects/parameter/satellitearray.h @@ -35,7 +35,6 @@ public: SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect); - virtual ~SatelliteArrayParam(); virtual Gtk::Widget *param_newWidget() { -- cgit v1.2.3 From ada767e2ad124b9dad0f80b7979a156513976aaa Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Jul 2015 12:20:05 +0200 Subject: pointwise tweak (bzr r13645.1.104) --- src/helper/geom-pointwise.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 7627b5dc3..db66162ca 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); } -- cgit v1.2.3 From 2207d9110e54540a7408642099c9217d8037a6b0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 6 Jul 2015 12:22:52 +0200 Subject: astyle (bzr r13645.1.105) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index db66162ca..91281ed7d 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 f5f28544d..ddef7685a 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 42c5687bd..ef76060c4 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 7871ccc1e..8998279a6 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -32,7 +32,7 @@ static const Util::EnumDataConverter FMConverter(FilletMethodData, LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), satellites_param(_("pair_array_param"), _("pair_array_param"), - "satellites_param", &wr, this), + "satellites_param", &wr, this), method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, @@ -264,13 +264,11 @@ void LPEFilletChamfer::updateAmount() std::vector satellites = pointwise->getSatellites(); Geom::Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector::iterator it = satellites.begin(); - it != satellites.end(); ++it) - { + it != satellites.end(); ++it) { Geom::Path sat_path = pathvector_before_effect.pathAt(it - satellites.begin()); size_t sat_curve_time = Geom::nearest_time(pathvector_before_effect.curveAt(it - satellites.begin()).initialPoint() , pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (!sat_path.closed() && sat_curve_time == first) - { + if (!sat_path.closed() && sat_curve_time == first) { it->amount = 0; continue; } @@ -278,19 +276,19 @@ void LPEFilletChamfer::updateAmount() continue; } boost::optional previous = boost::none; - if (sat_path.closed() && sat_curve_time == first){ + if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); previous = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first){ + } else if(!sat_path.closed() || sat_curve_time != first) { previous = sat_curve_time - 1; } if (only_selected) { Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); if (isNodePointSelected(satellite_point)) { if (!use_knot_distance && !flexible) { - if(previous){ + if(previous) { it->amount = it->radToLen(power, pwd2[*previous], - pwd2[it - satellites.begin()]); + pwd2[it - satellites.begin()]); } else { it->amount = 0.0; } @@ -300,12 +298,12 @@ void LPEFilletChamfer::updateAmount() } } else { if (!use_knot_distance && !flexible) { - if(previous){ + if(previous) { it->amount = it->radToLen(power, pwd2[*previous], - pwd2[it - satellites.begin()]); - } else { - it->amount = 0.0; - } + pwd2[it - satellites.begin()]); + } else { + it->amount = 0.0; + } } else { it->amount = power; } @@ -361,7 +359,7 @@ void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { - if(!_hp.empty()){ + if(!_hp.empty()) { _hp.clear(); } SPLPEItem *splpeitem = const_cast(lpeItem); @@ -382,7 +380,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); std::vector sats = satellites_param.data(); - if(sats.empty()){ + if(sats.empty()) { doOnApply(lpeItem); sats = satellites_param.data(); } @@ -413,7 +411,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } size_t number_curves = original_pathv.curveCount(); //if are diferent sizes call to poinwise recalculate - //todo: fire a reverse satellites on reverse path. Maybe a new method + //todo: fire a reverse satellites on reverse path. Maybe a new method //like "are_similar" to avoid precission issues on reverse a pointwise //and after convert to Pathvector if (pointwise && number_curves != sats.size()) { @@ -609,7 +607,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) double arc_angle = Geom::angle_between(x_line, angled_line); double radius = Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)) / - sin(angle / 2.0); + sin(angle / 2.0); Geom::Coord rx = radius; Geom::Coord ry = rx; if (times[1] != 1) { @@ -628,8 +626,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) - { + method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); @@ -648,8 +645,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) - { + method == FM_ARC) { path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { @@ -666,10 +662,9 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } else if (type == INVERSE_FILLET) { if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) - { + method == FM_ARC) { tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, - end_arc_point); + end_arc_point); } else { tmp_path.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); @@ -677,11 +672,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } else if (type == FILLET) { if ((is_straight_curve(*curve_it1) && is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || - method == FM_ARC) - { + method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, - end_arc_point); + end_arc_point); } else { tmp_path.appendNew(handle_1, handle_2, end_arc_point); diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index b7d403a91..5e45ddf0d 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -94,15 +94,15 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i].arcDistance(pwd2[i]); double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); double lenght_in = 0; - + Geom::Path sat_path = pointwise_pv.pathAt(i); boost::optional d2_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(i).initialPoint() , pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first){ + if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); d2_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first){ + } else if(!sat_path.closed() || sat_curve_time != first) { d2_prev_index = sat_curve_time - 1; } if (d2_prev_index) { @@ -298,10 +298,10 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, boost::optional d2_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first){ + if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); d2_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first){ + } else if(!sat_path.closed() || sat_curve_time != first) { d2_prev_index = sat_curve_time - 1; } if (d2_prev_index) { @@ -360,10 +360,10 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const boost::optional d2_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first){ + if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); d2_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first){ + } else if(!sat_path.closed() || sat_curve_time != first) { d2_prev_index = sat_curve_time - 1; } if (d2_prev_index) { @@ -454,13 +454,13 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) boost::optional d2_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first){ + if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); d2_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first){ + } else if(!sat_path.closed() || sat_curve_time != first) { d2_prev_index = sat_curve_time - 1; } - + if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { if (d2_prev_index) { amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*d2_prev_index], pwd2[index],_pparam->_vector.at(*d2_prev_index)); @@ -504,10 +504,10 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) boost::optional prev = boost::none; size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first){ + if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); prev = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first){ + } else if(!sat_path.closed() || sat_curve_time != first) { prev = sat_curve_time - 1; } if (prev) { -- cgit v1.2.3 From 6962e3344dea73a3bc7d5599cc223ed8cc7cdbe7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 21 Aug 2015 23:53:14 +0200 Subject: Not sure about this changes :( (bzr r13645.1.107) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 91281ed7d..526df7957 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 6a8ea8881..fe8f6f157 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 ddef7685a..9b2691a33 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 5e45ddf0d..9c22741ff 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -361,8 +361,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { - sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); - d2_prev_index = sat_curve_time + sat_path.size() - 1; + d2_prev_index = first + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { d2_prev_index = sat_curve_time - 1; } -- cgit v1.2.3 From 9e8b8be725180905f537a0c20183c209abc5476f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 22 Aug 2015 00:05:38 +0200 Subject: remove couts (bzr r13645.1.109) --- src/helper/geom-pointwise.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 526df7957..8a0db6258 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++; -- cgit v1.2.3 From 4f78e3e4289b52ba4b7a3fbe24fd0d6fcb6f2250 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 23 Aug 2015 23:03:12 +0200 Subject: satellites in curves (bzr r13645.1.110) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 8a0db6258..8ae2125a4 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 fe8f6f157..9d2993a23 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 9b2691a33..10afca725 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 ef76060c4..ed1ec221b 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 8998279a6..385e9ce28 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -85,19 +85,16 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { - Geom::PathVector const original_pathv = - pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); - Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); - pwd2_in = remove_short_cuts(pwd2_in, 0.01); + Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); int global_counter = 0; std::vector satellites; - for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); - path_it != original_pathv.end(); ++path_it) { + for (Geom::PathVector::const_iterator path_it = pathv.begin(); + path_it != pathv.end(); ++path_it) { if (path_it->empty()) { continue; } Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); + Geom::Path::const_iterator curve_endit = path_it->end_closed(); int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { @@ -106,6 +103,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) if (counter == 0) { if (!path_it->closed()) { active = false; + hidden = true; } } Satellite satellite(FILLET); @@ -123,9 +121,9 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } pointwise = new Pointwise(); - pointwise->setPwd2(pwd2_in); - pointwise->setSatellites(satellites); - pointwise->setStart(); + pointwise->setPathVector(pathv); + pointwise->setSatellites(satellites, false); + //pointwise->setStart(); satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -262,11 +260,14 @@ void LPEFilletChamfer::updateAmount() power = radius / 100; } std::vector satellites = pointwise->getSatellites(); + Geom::PathVector const pathv = pointwise->getPathVector(); + //todo 2GEOM I want to substiturte all Piecewise > whith a PathVector + //but is very dificult know the index of a curve inside a pathvector with current API Geom::Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - Geom::Path sat_path = pathvector_before_effect.pathAt(it - satellites.begin()); - size_t sat_curve_time = Geom::nearest_time(pathvector_before_effect.curveAt(it - satellites.begin()).initialPoint() , pwd2); + Geom::Path sat_path = pathv.pathAt(it - satellites.begin()); + size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(it - satellites.begin()).initialPoint() , pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (!sat_path.closed() && sat_curve_time == first) { it->amount = 0; @@ -282,25 +283,12 @@ void LPEFilletChamfer::updateAmount() } else if(!sat_path.closed() || sat_curve_time != first) { previous = sat_curve_time - 1; } - if (only_selected) { - Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); - if (isNodePointSelected(satellite_point)) { - if (!use_knot_distance && !flexible) { - if(previous) { - it->amount = it->radToLen(power, pwd2[*previous], - pwd2[it - satellites.begin()]); - } else { - it->amount = 0.0; - } - } else { - it->amount = power; - } - } - } else { + Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); + if (isNodePointSelected(satellite_point) || !only_selected) { if (!use_knot_distance && !flexible) { if(previous) { - it->amount = it->radToLen(power, pwd2[*previous], - pwd2[it - satellites.begin()]); + it->amount = it->radToLen(power, pathv.curveAt(*previous), + pathv.curveAt(it - satellites.begin())); } else { it->amount = 0.0; } @@ -375,31 +363,36 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //mandatory call satellites_param.setEffectType(effectType()); - Geom::PathVector const original_pathv = + Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Geom::Piecewise > pwd2_in = paths_to_pw(original_pathv); - pwd2_in = remove_short_cuts(pwd2_in, 0.01); - std::vector sats = satellites_param.data(); + Geom::Piecewise > pwd2 = paths_to_pw(pathv); + pwd2 = remove_short_cuts(pwd2, 0.01); + std::vector sats = normalizeSatellites(pathv, satellites_param.data()); if(sats.empty()) { doOnApply(lpeItem); - sats = satellites_param.data(); + sats = normalizeSatellites(pathv, satellites_param.data()); } if (hide_knots) { satellites_param.setHelperSize(0); } else { satellites_param.setHelperSize(helper_size); } + Geom::Curve const &first_curve = pathv.curveAt(0); + size_t number_curves = pathv.curveCount(); + //Activete cache + timeAtArcLength(1, first_curve, number_curves * 3); + arcLengthAt(1, first_curve, number_curves * 3); for (std::vector::iterator it = sats.begin(); it != sats.end();) { if (it->is_time != flexible) { it->is_time = flexible; double amount = it->amount; - Geom::D2 d2_in = pwd2_in[it - sats.begin()]; + Geom::Curve const &curve_in = pathv.curveAt(it - sats.begin()); if (it->is_time) { - double time = timeAtArcLength(amount, d2_in); + double time = timeAtArcLength(amount, curve_in); it->amount = time; } else { - double size = arcLengthAt(amount, d2_in); + double size = arcLengthAt(amount, curve_in); it->amount = size; } } @@ -409,7 +402,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) it->hidden = hide_knots; ++it; } - size_t number_curves = original_pathv.curveCount(); //if are diferent sizes call to poinwise recalculate //todo: fire a reverse satellites on reverse path. Maybe a new method //like "are_similar" to avoid precission issues on reverse a pointwise @@ -423,10 +415,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) sat.setAmount(0.0); sat.setAngle(0.0); sat.setSteps(0); - pointwise->recalculateForNewPwd2(pwd2_in, original_pathv, sat); + pointwise->recalculateForNewPwd2(pwd2, pathv, sat); } else { pointwise = new Pointwise(); - pointwise->setPwd2(pwd2_in); + pointwise->setPwd2(pwd2); pointwise->setSatellites(sats); } pointwise->setStart(); @@ -519,16 +511,16 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (first == counter) { if (sats.size() > first && sats[first].active) { time0 = - sats[first].time(path_it->begin()->duplicate()->toSBasis()); + sats[first].time(*path_it->begin()); } else { time0 = 0; } } - + Geom::Curve const &curve_it2_fixed_ref = *curve_it2_fixed; bool last = curve_it2 == curve_endit; - double s = satellite.arcDistance(curve_it2_fixed->toSBasis()); - double time1 = satellite.time(s, true, (*curve_it1).toSBasis()); - double time2 = satellite.time(curve_it2_fixed->toSBasis()); + double s = satellite.arcDistance(curve_it2_fixed_ref); + double time1 = satellite.time(s, true, (*curve_it1)); + double time2 = satellite.time(curve_it2_fixed_ref); if (!satellite.active) { time1 = 1; time2 = 0; @@ -552,15 +544,15 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } Geom::Point start_arc_point = knot_curve_1->finalPoint(); - Geom::Point end_arc_point = curve_it2_fixed->pointAt(times[2]); + Geom::Point end_arc_point = curve_it2_fixed_ref.pointAt(times[2]); if (times[2] == 1) { - end_arc_point = curve_it2_fixed->pointAt(times[2] - GAP_HELPER); + end_arc_point = curve_it2_fixed_ref.pointAt(times[2] - GAP_HELPER); } if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0] + GAP_HELPER); } double k1 = distance(start_arc_point, curve_it1->finalPoint()) * K; - double k2 = distance(end_arc_point, curve_it2_fixed->initialPoint()) * K; + double k2 = distance(end_arc_point, curve_it2_fixed_ref.initialPoint()) * K; Geom::CubicBezier const *cubic_1 = dynamic_cast(&*knot_curve_1); Geom::Ray ray_1(start_arc_point, curve_it1->finalPoint()); @@ -571,10 +563,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (time0 == 1) { handle_1 = start_arc_point; } - Geom::Curve *knot_curve_2 = curve_it2_fixed->portion(times[2], 1); + Geom::Curve *knot_curve_2 = curve_it2_fixed_ref.portion(times[2], 1); Geom::CubicBezier const *cubic_2 = dynamic_cast(&*knot_curve_2); - Geom::Ray ray_2(curve_it2_fixed->initialPoint(), end_arc_point); + Geom::Ray ray_2(curve_it2_fixed_ref.initialPoint(), end_arc_point); if (cubic_2) { ray_2.setPoints(end_arc_point, (*cubic_2)[1]); } @@ -597,7 +589,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } Geom::Point inverse_handle_2 = end_arc_point - Geom::Point::polar(handleAngle, k2); if (times[2] == 1) { - end_arc_point = curve_it2_fixed->pointAt(times[2]); + end_arc_point = curve_it2_fixed_ref.pointAt(times[2]); } if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0]); @@ -625,7 +617,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && - is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; path_chamfer.appendNew(rx, ry, arc_angle, 0, @@ -644,7 +636,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && - is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || method == FM_ARC) { path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); @@ -661,7 +653,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) tmp_path.appendNew(end_arc_point); } else if (type == INVERSE_FILLET) { if ((is_straight_curve(*curve_it1) && - is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || method == FM_ARC) { tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); @@ -671,7 +663,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } } else if (type == FILLET) { if ((is_straight_curve(*curve_it1) && - is_straight_curve(*curve_it2_fixed) && method != FM_BEZIER) || + is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 9c22741ff..ba1338daa 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -73,8 +73,9 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) if (!_last_pointwise) { return; } + Geom::Piecewise > pwd2 = _last_pointwise->getPwd2(); - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (mirror == true) { _hp.clear(); } @@ -86,21 +87,21 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) continue; } double pos = 0; - if (pwd2.size() <= i) { + if (pathv.size() <= i) { break; } - Geom::D2 d2 = pwd2[i]; + Geom::Curve &curve = const_cast(pathv.curveAt(i)); bool overflow = false; - double size_out = _vector[i].arcDistance(pwd2[i]); - double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); + double size_out = _vector[i].arcDistance(pathv.curveAt(i)); + double lenght_out = pathv.curveAt(i).length( Geom::EPSILON); double lenght_in = 0; - Geom::Path sat_path = pointwise_pv.pathAt(i); + Geom::Path sat_path = pathv.pathAt(i); boost::optional d2_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(i).initialPoint() , pwd2); + size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(i).initialPoint() , pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { - sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + //sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); d2_prev_index = sat_curve_time + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { d2_prev_index = sat_curve_time - 1; @@ -110,14 +111,14 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } if (mirror == true) { if (d2_prev_index) { - d2 = pwd2[*d2_prev_index]; - pos = _vector[i].time(size_out, true, d2); + curve = pathv.curveAt(*d2_prev_index); + pos = _vector[i].time(size_out, true, curve); if (lenght_out < size_out) { overflow = true; } } } else { - pos = _vector[i].time(d2); + pos = _vector[i].time(curve); if (lenght_in < size_out) { overflow = true; } @@ -125,8 +126,8 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) if (pos <= 0 || pos >= 1) { continue; } - Geom::Point point_a = d2.valueAt(pos); - Geom::Point deriv_a = unit_vector(derivative(d2).valueAt(pos)); + Geom::Point point_a = curve.pointAt(pos); + Geom::Point deriv_a = unit_vector(derivative(curve.toSBasis()).valueAt(pos)); Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); deriv_a = deriv_a * rot; Geom::Point point_c = point_a - deriv_a * _helper_size; @@ -141,7 +142,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } else { aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } - aff *= Geom::Translate(d2.valueAt(pos)); + aff *= Geom::Translate(curve.pointAt(pos)); pathv *= aff; _hp.push_back(pathv[0]); _hp.push_back(pathv[1]); @@ -171,7 +172,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } else { aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } - aff *= Geom::Translate(d2.valueAt(pos)); + aff *= Geom::Translate(curve.pointAt(pos)); pathv *= aff; _hp.push_back(pathv[0]); } @@ -292,36 +293,16 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (_index >= _pparam->_vector.size() ) { - Geom::Path sat_path = pointwise_pv.pathAt(index); - boost::optional d2_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first) { - sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); - d2_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - d2_prev_index = sat_curve_time - 1; - } - if (d2_prev_index) { - Geom::D2 d2_in = pwd2[*d2_prev_index]; - double mirror_time = Geom::nearest_time(s, d2_in); - double time_start = 0; - std::vector sats = pointwise->getSatellites(); - time_start = sats[*d2_prev_index].time(d2_in); - if (time_start > mirror_time) { - mirror_time = time_start; - } - double size = arcLengthAt(mirror_time, d2_in); - double amount = Geom::length(d2_in, Geom::EPSILON) - size; - if (satellite.is_time) { - amount = timeAtArcLength(amount, pwd2[index]); - } - satellite.amount = amount; + Geom::Path sat_path = pathv.pathAt(index); + if (sat_path.closed() && sat_path.front() == pathv.curveAt(index)) { + satellite.setPosition(s, sat_path.back(), true); + } else { + satellite.setPosition(s, pathv.curveAt(index-1), true); } } else { - satellite.setPosition(s, pwd2[index]); + satellite.setPosition(s, pathv.curveAt(index)); } _pparam->_vector.at(index) = satellite; SPLPEItem *splpeitem = dynamic_cast(item); @@ -349,41 +330,20 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const } Pointwise *pointwise = _pparam->_last_pointwise; Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (pwd2.size() <= index) { return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); if (_index >= _pparam->_vector.size()) { - tmp_point = satellite.getPosition(pwd2[index]); - Geom::Path sat_path = pointwise_pv.pathAt(index); - boost::optional d2_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first) { - d2_prev_index = first + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - d2_prev_index = sat_curve_time - 1; - } - if (d2_prev_index) { - Geom::D2 d2_in = pwd2[*d2_prev_index]; - double s = satellite.arcDistance(pwd2[index]); - double t = satellite.time(s, true, d2_in); - if (t > 1) { - t = 1; - } - if (t < 0) { - t = 0; - } - double time_start = 0; - time_start = pointwise->getSatellites()[*d2_prev_index].time(d2_in); - if (time_start > t) { - t = time_start; - } - tmp_point = (d2_in).valueAt(t); + Geom::Path sat_path = pathv.pathAt(index); + if (sat_path.closed() && sat_path.front() == pathv.curveAt(index)) { + tmp_point = satellite.getPosition(sat_path.back(), true); + } else { + tmp_point = satellite.getPosition(pathv.curveAt(index - 1), true); } } else { - tmp_point = satellite.getPosition(pwd2[index]); + tmp_point = satellite.getPosition(pathv.curveAt(index)); } Geom::Point const canvas_point = tmp_point; return canvas_point; @@ -447,11 +407,11 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } else if (state & GDK_SHIFT_MASK) { Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); double amount = _pparam->_vector.at(index).amount; - Geom::Path sat_path = pointwise_pv.pathAt(index); + Geom::Path sat_path = pathv.pathAt(index); boost::optional d2_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); @@ -462,18 +422,17 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { if (d2_prev_index) { - amount = _pparam->_vector.at(index).lenToRad(amount, pwd2[*d2_prev_index], pwd2[index],_pparam->_vector.at(*d2_prev_index)); + amount = _pparam->_vector.at(index).lenToRad(amount, pathv.curveAt(*d2_prev_index), pathv.curveAt(index),_pparam->_vector.at(*d2_prev_index)); } else { amount = 0.0; } } bool aprox = false; - Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; + Geom::Curve const &curve_out = pathv.curveAt(index); if (d2_prev_index) { - Geom::D2 d2_in = - _pparam->_last_pointwise->getPwd2()[*d2_prev_index]; - aprox = ((d2_in)[0].degreesOfFreedom() != 2 || - d2_out[0].degreesOfFreedom() != 2) && + Geom::Curve const &curve_in = pathv.curveAt(*d2_prev_index); + aprox = (curve_in.degreesOfFreedom() != 2 || + curve_out.degreesOfFreedom() != 2) && !_pparam->_use_distance ? true : false; @@ -498,19 +457,19 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Geom::PathVector pointwise_pv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - Geom::Path sat_path = pointwise_pv.pathAt(index); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::Path sat_path = pathv.pathAt(index); boost::optional prev = boost::none; - size_t sat_curve_time = Geom::nearest_time(pointwise_pv.curveAt(index).initialPoint(),pwd2); + size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { - sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); + //sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); prev = sat_curve_time + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { prev = sat_curve_time - 1; } if (prev) { - amount = _pparam->_vector.at(index).radToLen(amount, pwd2[*prev], pwd2[index]); + amount = _pparam->_vector.at(index).radToLen(amount, pathv.curveAt(*prev), pathv.curveAt(index)); } else { amount = 0.0; } -- cgit v1.2.3 From 89b565d68326ada49d11d0735ffb6b602c26a54f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 24 Aug 2015 00:58:37 +0200 Subject: Cached some functions (bzr r13645.1.111) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 8ae2125a4..9aa90df01 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 9d2993a23..a2324accd 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 10afca725..35d21ef32 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 385e9ce28..3fa011b38 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -94,7 +94,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) continue; } Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_closed(); + Geom::Path::const_iterator curve_endit = path_it->end_default(); int counter = 0; size_t steps = chamfer_steps; while (curve_it1 != curve_endit) { @@ -121,8 +121,8 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } pointwise = new Pointwise(); - pointwise->setPathVector(pathv); - pointwise->setSatellites(satellites, false); + pointwise->setPwd2(paths_to_pw(pathv)); + pointwise->setSatellites(satellites); //pointwise->setStart(); satellites_param.setPointwise(pointwise); } else { @@ -260,10 +260,10 @@ void LPEFilletChamfer::updateAmount() power = radius / 100; } std::vector satellites = pointwise->getSatellites(); - Geom::PathVector const pathv = pointwise->getPathVector(); //todo 2GEOM I want to substiturte all Piecewise > whith a PathVector //but is very dificult know the index of a curve inside a pathvector with current API Geom::Piecewise > pwd2 = pointwise->getPwd2(); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { Geom::Path sat_path = pathv.pathAt(it - satellites.begin()); @@ -367,10 +367,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Geom::Piecewise > pwd2 = paths_to_pw(pathv); pwd2 = remove_short_cuts(pwd2, 0.01); - std::vector sats = normalizeSatellites(pathv, satellites_param.data()); + std::vector sats = satellites_param.data(); if(sats.empty()) { doOnApply(lpeItem); - sats = normalizeSatellites(pathv, satellites_param.data()); + sats = satellites_param.data(); } if (hide_knots) { satellites_param.setHelperSize(0); diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index ba1338daa..6c3123f12 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -87,38 +87,37 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) continue; } double pos = 0; - if (pathv.size() <= i) { + if (pwd2.size() <= i) { break; } - Geom::Curve &curve = const_cast(pathv.curveAt(i)); + Geom::Curve *curve_in = pathv.curveAt(i).duplicate(); bool overflow = false; - double size_out = _vector[i].arcDistance(pathv.curveAt(i)); - double lenght_out = pathv.curveAt(i).length( Geom::EPSILON); + double size_out = _vector[i].arcDistance(*curve_in); + double lenght_out = curve_in->length(); double lenght_in = 0; Geom::Path sat_path = pathv.pathAt(i); - boost::optional d2_prev_index = boost::none; + boost::optional curve_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(i).initialPoint() , pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { - //sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); - d2_prev_index = sat_curve_time + sat_path.size() - 1; + curve_prev_index = sat_curve_time + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { - d2_prev_index = sat_curve_time - 1; + curve_prev_index = sat_curve_time - 1; } - if (d2_prev_index) { - lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); + if (curve_prev_index) { + lenght_in = pathv.curveAt(*curve_prev_index).length(); } if (mirror == true) { - if (d2_prev_index) { - curve = pathv.curveAt(*d2_prev_index); - pos = _vector[i].time(size_out, true, curve); + if (curve_prev_index) { + curve_in = const_cast(&pathv.curveAt(*curve_prev_index)); + pos = _vector[i].time(size_out, true, *curve_in); if (lenght_out < size_out) { overflow = true; } } } else { - pos = _vector[i].time(curve); + pos = _vector[i].time(*curve_in); if (lenght_in < size_out) { overflow = true; } @@ -126,8 +125,8 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) if (pos <= 0 || pos >= 1) { continue; } - Geom::Point point_a = curve.pointAt(pos); - Geom::Point deriv_a = unit_vector(derivative(curve.toSBasis()).valueAt(pos)); + Geom::Point point_a = curve_in->pointAt(pos); + Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos)); Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); deriv_a = deriv_a * rot; Geom::Point point_c = point_a - deriv_a * _helper_size; @@ -142,7 +141,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } else { aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } - aff *= Geom::Translate(curve.pointAt(pos)); + aff *= Geom::Translate(curve_in->pointAt(pos)); pathv *= aff; _hp.push_back(pathv[0]); _hp.push_back(pathv[1]); @@ -172,7 +171,7 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) } else { aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); } - aff *= Geom::Translate(curve.pointAt(pos)); + aff *= Geom::Translate(curve_in->pointAt(pos)); pathv *= aff; _hp.push_back(pathv[0]); } @@ -296,10 +295,29 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (_index >= _pparam->_vector.size() ) { Geom::Path sat_path = pathv.pathAt(index); - if (sat_path.closed() && sat_path.front() == pathv.curveAt(index)) { - satellite.setPosition(s, sat_path.back(), true); - } else { - satellite.setPosition(s, pathv.curveAt(index-1), true); + boost::optional curve_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); + if (sat_path.closed() && sat_curve_time == first) { + curve_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first) { + curve_prev_index = sat_curve_time - 1; + } + if (curve_prev_index) { + Geom::Curve const &curve_in = pathv.curveAt(*curve_prev_index); + double mirror_time = Geom::nearest_time(s, curve_in); + double time_start = 0; + std::vector sats = pointwise->getSatellites(); + time_start = sats[*curve_prev_index].time(curve_in); + if (time_start > mirror_time) { + mirror_time = time_start; + } + double size = arcLengthAt(mirror_time, curve_in); + double amount = curve_in.length() - size; + if (satellite.is_time) { + amount = timeAtArcLength(amount, pathv.curveAt(index)); + } + satellite.amount = amount; } } else { satellite.setPosition(s, pathv.curveAt(index)); @@ -336,11 +354,32 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const } this->knot->show(); if (_index >= _pparam->_vector.size()) { + tmp_point = satellite.getPosition(pathv.curveAt(index)); Geom::Path sat_path = pathv.pathAt(index); - if (sat_path.closed() && sat_path.front() == pathv.curveAt(index)) { - tmp_point = satellite.getPosition(sat_path.back(), true); - } else { - tmp_point = satellite.getPosition(pathv.curveAt(index - 1), true); + boost::optional curve_prev_index = boost::none; + size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); + size_t first = Geom::nearest_time(sat_path.initialPoint(), pwd2); + if (sat_path.closed() && sat_curve_time == first) { + curve_prev_index = sat_curve_time + sat_path.size() - 1; + } else if(!sat_path.closed() || sat_curve_time != first) { + curve_prev_index = sat_curve_time - 1; + } + if (curve_prev_index) { + Geom::Curve const &curve_in = pathv.curveAt(*curve_prev_index); + double s = satellite.arcDistance(pathv.curveAt(index)); + double t = satellite.time(s, true, curve_in); + if (t > 1) { + t = 1; + } + if (t < 0) { + t = 0; + } + double time_start = 0; + time_start = pointwise->getSatellites()[*curve_prev_index].time(curve_in); + if (time_start > t) { + t = time_start; + } + tmp_point = (curve_in).pointAt(t); } } else { tmp_point = satellite.getPosition(pathv.curveAt(index)); @@ -410,29 +449,28 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); double amount = _pparam->_vector.at(index).amount; Geom::Path sat_path = pathv.pathAt(index); - boost::optional d2_prev_index = boost::none; + boost::optional curve_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { - sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); - d2_prev_index = sat_curve_time + sat_path.size() - 1; + curve_prev_index = sat_curve_time + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { - d2_prev_index = sat_curve_time - 1; + curve_prev_index = sat_curve_time - 1; } - if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { - if (d2_prev_index) { - amount = _pparam->_vector.at(index).lenToRad(amount, pathv.curveAt(*d2_prev_index), pathv.curveAt(index),_pparam->_vector.at(*d2_prev_index)); + if (curve_prev_index) { + amount = _pparam->_vector.at(index).lenToRad(amount, pathv.curveAt(*curve_prev_index), pathv.curveAt(index), _pparam->_vector.at(*curve_prev_index)); } else { amount = 0.0; } } bool aprox = false; - Geom::Curve const &curve_out = pathv.curveAt(index); - if (d2_prev_index) { - Geom::Curve const &curve_in = pathv.curveAt(*d2_prev_index); - aprox = (curve_in.degreesOfFreedom() != 2 || - curve_out.degreesOfFreedom() != 2) && + Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; + if (curve_prev_index) { + Geom::D2 d2_in = + _pparam->_last_pointwise->getPwd2()[*curve_prev_index]; + aprox = ((d2_in)[0].degreesOfFreedom() != 2 || + d2_out[0].degreesOfFreedom() != 2) && !_pparam->_use_distance ? true : false; @@ -463,7 +501,6 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); if (sat_path.closed() && sat_curve_time == first) { - //sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); prev = sat_curve_time + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { prev = sat_curve_time - 1; -- cgit v1.2.3 From d34b8dca901083e5b68fd22899cb2c014238f8a4 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 25 Aug 2015 13:39:35 +0200 Subject: addes cache and log to a function, result of the test, no diference so remove cache on next commit (bzr r13645.1.112) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index 35d21ef32..fac314b7f 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 ed1ec221b..61ac6be75 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 3fa011b38..a83c7bbd5 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -55,6 +55,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), + cache(_("Cache size:"),_("Cache size"), "cache_size", &wr, this, 3), pointwise(NULL) { registerParameter(&satellites_param); @@ -68,6 +69,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) registerParameter(&ignore_radius_0); registerParameter(&only_selected); registerParameter(&hide_knots); + registerParameter(&cache); radius.param_set_range(0.0, Geom::infinity()); radius.param_set_increments(1, 1); @@ -78,6 +80,9 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) helper_size.param_set_range(0, 999); helper_size.param_set_increments(5, 5); helper_size.param_set_digits(0); + cache.param_set_range(0, 999); + cache.param_set_increments(1, 1); + cache.param_set_digits(0); } void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) @@ -380,8 +385,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Geom::Curve const &first_curve = pathv.curveAt(0); size_t number_curves = pathv.curveCount(); //Activete cache - timeAtArcLength(1, first_curve, number_curves * 3); - arcLengthAt(1, first_curve, number_curves * 3); + timeAtArcLength(1, first_curve, number_curves * cache); for (std::vector::iterator it = sats.begin(); it != sats.end();) { if (it->is_time != flexible) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 804709342..9c58ab66c 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -58,6 +58,7 @@ private: BoolParam hide_knots; BoolParam ignore_radius_0; ScalarParam helper_size; + ScalarParam cache; Pointwise *pointwise; Geom::PathVector _hp; -- cgit v1.2.3 From 6d0ce49991a442e7e3f26c3922c26e54d927dd93 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 25 Aug 2015 13:48:02 +0200 Subject: Removed cache work :( (bzr r13645.1.113) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-satellite.cpp b/src/helper/geom-satellite.cpp index fac314b7f..547caf539 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 61ac6be75..2369dddbd 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 a83c7bbd5..4c325b7fa 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -55,7 +55,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - cache(_("Cache size:"),_("Cache size"), "cache_size", &wr, this, 3), pointwise(NULL) { registerParameter(&satellites_param); @@ -69,7 +68,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) registerParameter(&ignore_radius_0); registerParameter(&only_selected); registerParameter(&hide_knots); - registerParameter(&cache); radius.param_set_range(0.0, Geom::infinity()); radius.param_set_increments(1, 1); @@ -80,9 +78,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) helper_size.param_set_range(0, 999); helper_size.param_set_increments(5, 5); helper_size.param_set_digits(0); - cache.param_set_range(0, 999); - cache.param_set_increments(1, 1); - cache.param_set_digits(0); } void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) @@ -382,10 +377,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { satellites_param.setHelperSize(helper_size); } - Geom::Curve const &first_curve = pathv.curveAt(0); size_t number_curves = pathv.curveCount(); - //Activete cache - timeAtArcLength(1, first_curve, number_curves * cache); for (std::vector::iterator it = sats.begin(); it != sats.end();) { if (it->is_time != flexible) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 9c58ab66c..804709342 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -58,7 +58,6 @@ private: BoolParam hide_knots; BoolParam ignore_radius_0; ScalarParam helper_size; - ScalarParam cache; Pointwise *pointwise; Geom::PathVector _hp; -- cgit v1.2.3 From 4b21c95466fd2e108caccafb3feb1d17e5055431 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 26 Aug 2015 21:34:58 +0200 Subject: add 'little' comment (bzr r13645.1.114) --- src/live_effects/lpe-fillet-chamfer.cpp | 1 - src/live_effects/parameter/satellitearray.cpp | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 4c325b7fa..24ed983fd 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -278,7 +278,6 @@ void LPEFilletChamfer::updateAmount() } boost::optional previous = boost::none; if (sat_path.closed() && sat_curve_time == first) { - sat_curve_time = Geom::nearest_time(sat_path.initialPoint(),pwd2); previous = sat_curve_time + sat_path.size() - 1; } else if(!sat_path.closed() || sat_curve_time != first) { previous = sat_curve_time - 1; diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index 6c3123f12..ab2b9fe2e 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -294,6 +294,16 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Piecewise > pwd2 = pointwise->getPwd2(); Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); if (_index >= _pparam->_vector.size() ) { + //I want to remplace this whith patvectorTime but need a way to know the index of a curve in a pathvector + //Geom::Path sat_path = pathv.pathAt(index); + //PathTime sat_time = sat_path.nearestTime(pathv.curveAt(index).initialPoint()); + //boost::optional previous_index = boost::none; + //if (sat_path.closed() && sat_time.curve_index == 0) { + // previous_index = sat_path.size(); + //} else if(!sat_path.closed() || sat_time.curve_index != 0) { + // previous_index = sat_time.curve_index - 1; + //} + //if (previous_index) { Geom::Path sat_path = pathv.pathAt(index); boost::optional curve_prev_index = boost::none; size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); -- cgit v1.2.3 From be65fc811e309e3a126f272601c3cb7997ef465e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 26 Aug 2015 22:09:46 +0200 Subject: 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(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 9aa90df01..7074761da 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 547caf539..615106dd9 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) { -- cgit v1.2.3 From 67753b095a9a4c3ce0f22a3c63b5adb863c087ed Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 1 Sep 2015 21:54:18 +0200 Subject: Update to limit options to radius = 0, radious > 0 or both (bzr r13645.1.118) --- src/live_effects/lpe-fillet-chamfer.cpp | 19 +++++++++++++------ src/live_effects/lpe-fillet-chamfer.h | 3 ++- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 24ed983fd..8c3b6e2f1 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -51,8 +51,8 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) "use_knot_distance", &wr, this, false), hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), - ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), - "ignore_radius_0", &wr, this, false), + apply_no_radius(_("Apply changes if radius = 0"), _("Apply changes if radius = 0"), "apply_no_radius", &wr, this, true), + apply_with_radius(_("Apply changes if radius > 0"), _("Apply changes if radius > 0"), "apply_with_radius", &wr, this, true), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), pointwise(NULL) @@ -65,7 +65,8 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) registerParameter(&flexible); registerParameter(&use_knot_distance); registerParameter(&mirror_knots); - registerParameter(&ignore_radius_0); + registerParameter(&apply_no_radius); + registerParameter(&apply_with_radius); registerParameter(&only_selected); registerParameter(&hide_knots); @@ -273,7 +274,9 @@ void LPEFilletChamfer::updateAmount() it->amount = 0; continue; } - if (ignore_radius_0 && it->amount == 0) { + if ((!apply_no_radius && it->amount == 0) || + (!apply_with_radius && it->amount != 0)) + { continue; } boost::optional previous = boost::none; @@ -306,7 +309,9 @@ void LPEFilletChamfer::updateChamferSteps() Geom::Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if (ignore_radius_0 && it->amount == 0) { + if ((!apply_no_radius && it->amount == 0) || + (!apply_with_radius && it->amount != 0)) + { continue; } if (only_selected) { @@ -328,7 +333,9 @@ void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) Geom::Piecewise > pwd2 = pointwise->getPwd2(); for (std::vector::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if (ignore_radius_0 && it->amount == 0) { + if ((!apply_no_radius && it->amount == 0) || + (!apply_with_radius && it->amount != 0)) + { continue; } if (only_selected) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 804709342..638e8c6af 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -56,7 +56,8 @@ private: BoolParam only_selected; BoolParam use_knot_distance; BoolParam hide_knots; - BoolParam ignore_radius_0; + BoolParam apply_no_radius; + BoolParam apply_with_radius; ScalarParam helper_size; Pointwise *pointwise; -- cgit v1.2.3 From 7fee08f7ade15cbba3932dd745492779e7e01987 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 16 Mar 2016 00:17:44 +0100 Subject: Fixed bugs post merge (bzr r13645.1.120) --- src/live_effects/parameter/satellitearray.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp index ab2b9fe2e..1615f33e2 100644 --- a/src/live_effects/parameter/satellitearray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -137,9 +137,9 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) Geom::Affine aff = Geom::Affine(); aff *= Geom::Scale(_helper_size); if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(90)); + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); } else { - aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); } aff *= Geom::Translate(curve_in->pointAt(pos)); pathv *= aff; @@ -167,9 +167,9 @@ void SatelliteArrayParam::updateCanvasIndicators(bool mirror) aff = Geom::Affine(); aff *= Geom::Scale(_helper_size / 2.0); if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(90)); + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); } else { - aff *= Geom::Rotate(ray_1.angle() - Geom::deg_to_rad(270)); + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); } aff *= Geom::Translate(curve_in->pointAt(pos)); pathv *= aff; -- cgit v1.2.3 From 01836c90d5d768fe4f189bf066cb4ed800196d8d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 16 Mar 2016 07:59:18 +0100 Subject: Remove advertaising buttons of old version (bzr r13645.1.123) --- src/live_effects/lpe-fillet-chamfer.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index d91225cb7..896cf2e69 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -146,14 +146,6 @@ Gtk::Widget *LPEFilletChamfer::newWidget() vbox->set_border_width(5); vbox->set_homogeneous(false); vbox->set_spacing(2); - Gtk::HBox *advertaising = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *advert = Gtk::manage(new Gtk::Button(Glib::ustring(_("IMPORTANT! New version soon...")))); - advertaising->pack_start(*advert, true, true, 2); - vbox->pack_start(*advertaising, true, true, 2); - Gtk::HBox *advertaising2 = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *advert2 = Gtk::manage(new Gtk::Button(Glib::ustring(_("Not compatible. Convert to path after.")))); - advertaising2->pack_start(*advert2, true, true, 2); - vbox->pack_start(*advertaising2, true, true, 2); std::vector::iterator it = param_vector.begin(); while (it != param_vector.end()) { if ((*it)->widget_is_visible) { -- cgit v1.2.3 From 90fa52d140c68277789d5c87b86bd7a73969458d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 8 Apr 2016 18:03:17 +0200 Subject: remove a waring on compile (bzr r13645.1.126) --- src/live_effects/lpe-fillet-chamfer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 896cf2e69..956395623 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -609,7 +609,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Coord rx = radius; Geom::Coord ry = rx; if (times[1] != 1) { - if (times[1] != times[0] || times[1] == times[0] == 1) { + if (times[1] != times[0] || (times[1] == 1 && times[0] == 1)) { if (!knot_curve_1->isDegenerate()) { tmp_path.append(*knot_curve_1); } -- cgit v1.2.3 From 97bd182d6a2113eab1dd5faf51402ebd5382791c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 8 May 2016 22:57:37 +0200 Subject: First attempt to make fixed tweenk review (bzr r13645.1.128) --- src/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 ------------------------- src/live_effects/parameter/satellitearray.h | 114 ----- src/live_effects/parameter/satellitesarray.cpp | 527 +++++++++++++++++++++++ src/live_effects/parameter/satellitesarray.h | 115 ++++++ 15 files changed, 941 insertions(+), 1126 deletions(-) delete mode 100644 src/live_effects/parameter/satellitearray.cpp delete mode 100644 src/live_effects/parameter/satellitearray.h create mode 100644 src/live_effects/parameter/satellitesarray.cpp create mode 100644 src/live_effects/parameter/satellitesarray.h (limited to 'src') diff --git a/src/2geom/2geom.h b/src/2geom/2geom.h index e9222ba84..813e243b3 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 e38594547..97b47b630 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 7074761da..a96b7cbda 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 a2324accd..4c2ec7957 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 615106dd9..027497d78 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 2369dddbd..6cf891ec5 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 956395623..bcab1c055 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -91,39 +91,30 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) SPShape *shape = dynamic_cast(splpeitem); if (shape) { Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); - int global_counter = 0; - std::vector satellites; - for (Geom::PathVector::const_iterator path_it = pathv.begin(); - path_it != pathv.end(); ++path_it) { + Satellites satellites; + for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { if (path_it->empty()) { continue; } + std::vector subpath_satellites; Geom::Path::const_iterator curve_it1 = path_it->begin(); Geom::Path::const_iterator curve_endit = path_it->end_default(); - int counter = 0; - size_t steps = chamfer_steps; + bool start = true; while (curve_it1 != curve_endit) { - bool active = true; bool hidden = false; - if (counter == 0) { + if (start) { if (!path_it->closed()) { - active = false; hidden = true; } + start = false; } Satellite satellite(FILLET); - satellite.setIsTime(flexible); - satellite.setActive(active); - satellite.setHasMirror(mirror_knots); satellite.setHidden(hidden); - satellite.setAmount(0.0); - satellite.setAngle(0.0); - satellite.setSteps(steps); - satellites.push_back(satellite); + satellite.setSteps(chamfer_steps); + subpath_satellites.push_back(satellite); ++curve_it1; - counter++; - global_counter++; } + satellites.push_back(subpath_satellites); } pointwise = new Pointwise(); pointwise->setPwd2(paths_to_pw(pathv)); @@ -264,42 +255,36 @@ void LPEFilletChamfer::updateAmount() } else { power = radius / 100; } - std::vector satellites = pointwise->getSatellites(); - //todo 2GEOM I want to substiturte all Piecewise > whith a PathVector - //but is very dificult know the index of a curve inside a pathvector with current API - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - for (std::vector::iterator it = satellites.begin(); - it != satellites.end(); ++it) { - Geom::Path sat_path = pathv.pathAt(it - satellites.begin()); - size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(it - satellites.begin()).initialPoint() , pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (!sat_path.closed() && sat_curve_time == first) { - it->amount = 0; - continue; - } - if ((!apply_no_radius && it->amount == 0) || - (!apply_with_radius && it->amount != 0)) - { - continue; - } - boost::optional previous = boost::none; - if (sat_path.closed() && sat_curve_time == first) { - previous = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - previous = sat_curve_time - 1; - } - Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); - if (isNodePointSelected(satellite_point) || !only_selected) { - if (!use_knot_distance && !flexible) { - if(previous) { - it->amount = it->radToLen(power, pathv.curveAt(*previous), - pathv.curveAt(it - satellites.begin())); + Satellites satellites = pointwise->getSatellites(); + Geom::PathVector pathv = pointwise->getPV(); + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + boost::optional curve_prev_index = boost::none; + if(j == 0 && pathv[i].closed()){ + curve_prev_index = pathv[pathv[i].size() - 1]; + } else if(!pathv[i].closed() || j != 0) { + curve_prev_index = j - 1; + } + if (!pathv[i].closed() && sat_curve_time == 0) { + it->amount = 0; + continue; + } + if ((!apply_no_radius && it->amount == 0) || + (!apply_with_radius && it->amount != 0)) + { + continue; + } + Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); + if (isNodePointSelected(satellite_point) || !only_selected) { + if (!use_knot_distance && !flexible) { + if(curve_prev_index) { + it->amount = it->radToLen(power, pathv[i][*curve_prev_index], pathv[i][j]); + } else { + it->amount = 0.0; + } } else { - it->amount = 0.0; + it->amount = power; } - } else { - it->amount = power; } } } @@ -310,21 +295,22 @@ void LPEFilletChamfer::updateAmount() void LPEFilletChamfer::updateChamferSteps() { std::vector satellites = pointwise->getSatellites(); - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); - it != satellites.end(); ++it) { - if ((!apply_no_radius && it->amount == 0) || - (!apply_with_radius && it->amount != 0)) - { - continue; - } - if (only_selected) { - Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); - if (isNodePointSelected(satellite_point)) { - it->steps = chamfer_steps; + Geom::PathVector pathv = pointwise->getPV(); + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + if ((!apply_no_radius && satellites[i][j]->amount == 0) || + (!apply_with_radius && satellites[i][j]->amount != 0)) + { + continue; + } + if (only_selected) { + Geom::Point satellite_point = pathv[i].pointAt(j); + if (isNodePointSelected(satellite_point)) { + satellites[i][j]->steps = chamfer_steps; + } + } else { + satellites[i][j]->steps = chamfer_steps; } - } else { - it->steps = chamfer_steps; } } pointwise->setSatellites(satellites); @@ -334,21 +320,22 @@ void LPEFilletChamfer::updateChamferSteps() void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { std::vector satellites = pointwise->getSatellites(); - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - for (std::vector::iterator it = satellites.begin(); - it != satellites.end(); ++it) { - if ((!apply_no_radius && it->amount == 0) || - (!apply_with_radius && it->amount != 0)) - { - continue; - } - if (only_selected) { - Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); - if (isNodePointSelected(satellite_point)) { - it->satellite_type = satellitetype; + Geom::PathVector pathv = pointwise->getPV(); + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + if ((!apply_no_radius && satellites[i][j]->amount == 0) || + (!apply_with_radius && satellites[i][j]->amount != 0)) + { + continue; + } + if (only_selected) { + Geom::Point satellite_point = pathv[i].pointAt(j); + if (isNodePointSelected(satellite_point)) { + satellites[i][j]->satellite_type = satellitetype; + } + } else { + satellites[i][j]->satellite_type = satellitetype; } - } else { - it->satellite_type = satellitetype; } } pointwise->setSatellites(satellites); @@ -373,14 +360,13 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //mandatory call satellites_param.setEffectType(effectType()); - Geom::PathVector const pathv = - pathv_to_linear_and_cubic_beziers(c->get_pathvector()); + Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Geom::Piecewise > pwd2 = paths_to_pw(pathv); pwd2 = remove_short_cuts(pwd2, 0.01); - std::vector sats = satellites_param.data(); - if(sats.empty()) { + Satellites satelites = satellites_param.data(); + if(satelites.empty()) { doOnApply(lpeItem); - sats = satellites_param.data(); + satelites = satellites_param.data(); } if (hide_knots) { satellites_param.setHelperSize(0); @@ -388,44 +374,39 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites_param.setHelperSize(helper_size); } size_t number_curves = pathv.curveCount(); - for (std::vector::iterator it = sats.begin(); - it != sats.end();) { - if (it->is_time != flexible) { - it->is_time = flexible; - double amount = it->amount; - Geom::Curve const &curve_in = pathv.curveAt(it - sats.begin()); - if (it->is_time) { - double time = timeAtArcLength(amount, curve_in); - it->amount = time; - } else { - double size = arcLengthAt(amount, curve_in); - it->amount = size; + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + if (satellites[i][j]->is_time != flexible) { + satellites[i][j]->is_time = flexible; + double amount = satellites[i][j]->amount; + Geom::Curve const &curve_in = pathv[i][j]; + if (satellites[i][j]->is_time) { + double time = timeAtArcLength(amount, curve_in); + satellites[i][j]->amount = time; + } else { + double size = arcLengthAt(amount, curve_in); + satellites[i][j]->amount = size; + } } + if (satellites[i][j]->has_mirror != mirror_knots) { + satellites[i][j]->has_mirror = mirror_knots; + } + satellites[i][j]->hidden = hide_knots; } - if (it->has_mirror != mirror_knots) { - it->has_mirror = mirror_knots; - } - it->hidden = hide_knots; - ++it; } //if are diferent sizes call to poinwise recalculate //todo: fire a reverse satellites on reverse path. Maybe a new method //like "are_similar" to avoid precission issues on reverse a pointwise //and after convert to Pathvector - if (pointwise && number_curves != sats.size()) { - Satellite sat(sats[0].satellite_type); - sat.setIsTime(sats[0].is_time); - sat.setActive(true); - sat.setHasMirror( sats[0].has_mirror); - sat.setHidden(false); - sat.setAmount(0.0); - sat.setAngle(0.0); - sat.setSteps(0); - pointwise->recalculateForNewPwd2(pwd2, pathv, sat); + if (pointwise && number_curves != pointwise->getTotalSatellites()) { + Satellite satellite(satellites[0][0].satellite_type); + satellite.setIsTime(satellites[0][0].is_time); + satellite.setHasMirror(satellites[0][0].has_mirror); + pointwise->recalculateForNewPwd2(pwd2, pathv, satellite); } else { pointwise = new Pointwise(); pointwise->setPwd2(pwd2); - pointwise->setSatellites(sats); + pointwise->setSatellites(satellites); } pointwise->setStart(); satellites_param.setPointwise(pointwise); @@ -446,12 +427,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) { const double GAP_HELPER = 0.00001; Geom::PathVector path_out; - size_t counter = 0; + size_t counter_paths = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - Geom::PathVector path_in_processed = - pathv_to_linear_and_cubic_beziers(path_in); - for (Geom::PathVector::const_iterator path_it = path_in_processed.begin(); - path_it != path_in_processed.end(); ++path_it) { + Geom::PathVector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); + for (Geom::PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { if (path_it->empty()) { continue; } @@ -470,14 +449,13 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) size_t counter_curves = 0; size_t first = counter; double time0 = 0; - std::vector sats = pointwise->getSatellites(); + Satellites satelites = pointwise->getSatellites(); while (curve_it1 != curve_endit) { if (curve_it2 != curve_endit && (*curve_it2).isDegenerate()) { ++curve_it2; } if ((*curve_it1).isDegenerate()) { ++curve_it1; - counter++; counter_curves++; time0 = 0.0; continue; @@ -487,8 +465,8 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (!path_it->closed()) { if (curve_it2 != curve_endit) { curve_it2_fixed = (*curve_it2).duplicate(); - if (sats.size() > counter + 1) { - satellite = sats[counter + 1]; + if (satellites[counter_paths].size() > counter_curves + 1) { + satellite = satellites[counter_paths][counter_curves + 1]; } } else { if (time0 != 1) { @@ -497,27 +475,25 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) tmp_path.append(*last_curve); } ++curve_it1; - counter++; counter_curves++; continue; } } else { if (curve_it2 != curve_endit) { curve_it2_fixed = (*curve_it2).duplicate(); - if (sats.size() > counter + 1) { - satellite = sats[counter + 1]; + if (satellites[counter_paths].size() > counter_curves + 1) { + satellite = satellites[counter_paths][counter_curves + 1];; } } else { - if (sats.size() > first) { - satellite = sats[first]; + if (satellites[counter_paths].size() > 0) { + satellite = satellites[counter_paths][0]; } } } - if (first == counter) { - if (sats.size() > first && sats[first].active) { - time0 = - sats[first].time(*path_it->begin()); + if (counter_curves == 0) { + if (satellites[counter_paths].size() > 0 && satellites[counter_paths][0].active) { + time0 = satellites[counter_paths][0].time(*path_it->begin()); } else { time0 = 0; } @@ -691,10 +667,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (curve_it2 != curve_endit) { ++curve_it2; } - counter++; counter_curves++; time0 = times[2]; } + counter_paths++; path_out.push_back(tmp_path); } return path_out; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 638e8c6af..a209971dd 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -13,7 +13,7 @@ */ #include "live_effects/parameter/enum.h" -#include "live_effects/parameter/satellitearray.h" +#include "live_effects/parameter/satellitesarray.h" #include "live_effects/effect.h" #include "helper/geom-pointwise.h" @@ -45,7 +45,7 @@ public: void fillet(); void inverseFillet(); - SatelliteArrayParam satellites_param; + SatellitesArrayParam satellites_param; private: EnumParam method; diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index 9a0ebe235..ab4a8eb4e 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -22,8 +22,8 @@ ink_common_sources += \ live_effects/parameter/originalpatharray.h \ live_effects/parameter/powerstrokepointarray.cpp \ live_effects/parameter/powerstrokepointarray.h \ - live_effects/parameter/satellitearray.cpp \ - live_effects/parameter/satellitearray.h \ + live_effects/parameter/satellitesarray.cpp \ + live_effects/parameter/satellitesarray.h \ live_effects/parameter/text.cpp \ live_effects/parameter/text.h \ live_effects/parameter/transformedpoint.cpp \ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 0abcd4b9b..0bbe39293 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -13,35 +13,43 @@ namespace Inkscape { namespace LivePathEffect { -//TODO: move maybe to svg-lenght.cpp +//TODO: move maybe unsigned int -sp_svg_satellite_read_d(gchar const *str, Satellite *sat){ +sp_svg_satellite_vector_read_d(gchar const *str, std::vector *satellites){ if (!str) { return 0; } - gchar ** strarray = g_strsplit(str, ",", 8); - if(strlen(str) > 0 && strarray[7] && !strarray[8]){ - sat->setSatelliteType(g_strstrip(strarray[0])); - sat->is_time = strncmp(strarray[1],"1",1) == 0; - sat->active = strncmp(strarray[2],"1",1) == 0; - sat->has_mirror = strncmp(strarray[3],"1",1) == 0; - sat->hidden = strncmp(strarray[4],"1",1) == 0; - double amount,angle; - float stepsTmp; - sp_svg_number_read_d(strarray[5], &amount); - sp_svg_number_read_d(strarray[6], &angle); - sp_svg_number_read_f(strarray[7], &stepsTmp); - unsigned int steps = (unsigned int)stepsTmp; - sat->amount = amount; - sat->angle = angle; - sat->steps = steps; - g_strfreev (strarray); - return 1; + gchar ** strarray = g_strsplit(str, "@", 0); + for (size_t i = 0; i < strarray.size(); ++i) { + gchar ** strsubarray = g_strsplit(strarray[i], ",", 7); + if(strlen(str) > 0 && strsubarray[6] && !strsubarray[7]){ + Satellite sat; + sat->setSatelliteType(g_strstrip(strsubarray[0])); + sat->is_time = strncmp(strsubarray[1],"1",1) == 0; + sat->has_mirror = strncmp(strsubarray[2],"1",1) == 0; + sat->hidden = strncmp(strsubarray[3],"1",1) == 0; + double amount,angle; + float stepsTmp; + sp_svg_number_read_d(strsubarray[4], &amount); + sp_svg_number_read_d(strsubarray[5], &angle); + sp_svg_number_read_f(strsubarray[6], &stepsTmp); + unsigned int steps = (unsigned int)stepsTmp; + sat->amount = amount; + sat->angle = angle; + sat->steps = steps; + g_strfreev (strsubarray); + satellites.push_back(sat); + } + g_strfreev (strsubarray); } g_strfreev (strarray); + if (!sat.empty()){ + return 1; + } return 0; } + template <> double ArrayParam::readsvg(const gchar * str) @@ -75,25 +83,20 @@ ArrayParam::readsvg(const gchar * str) return Geom::Point(Geom::infinity(),Geom::infinity()); } + template <> -Satellite -ArrayParam::readsvg(const gchar * str) +std::vector +ArrayParam >::readsvg(const gchar * str) { - Satellite sat; - if (sp_svg_satellite_read_d(str, &sat)) { - return sat; + std::vector satellites; + if (sp_svg_satellite_vector_read_d(str, &satellites)) { + return satellites; } - Satellite satellite(FILLET); - satellite.setIsTime(true); - satellite.setActive(false); - satellite.setHasMirror(false); - satellite.setHidden(true); - satellite.setAmount(0.0); - satellite.setAngle(0.0); - satellite.setSteps(0); - return satellite; + satellites.push_back(Satellite satellite(FILLET)); + return satellites; } + } /* namespace LivePathEffect */ } /* namespace Inkscape */ diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 66ed6344b..7076a465f 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -110,22 +110,25 @@ protected: str << nVector; } - void writesvgData(SVGOStringStream &str, Satellite const &nVector) const { - str << nVector.getSatelliteTypeGchar(); - str << ","; - str << nVector.is_time; - str << ","; - str << nVector.active; - str << ","; - str << nVector.has_mirror; - str << ","; - str << nVector.hidden; - str << ","; - str << nVector.amount; - str << ","; - str << nVector.angle; - str << ","; - str << nVector.steps; + void writesvgData(SVGOStringStream &str, std::vector const &nVector) const { + for (size_t i = 0; i < nVector.size(); ++i) { + str << nVector[i].getSatelliteTypeGchar(); + str << ","; + str << nVector[i].is_time; + str << ","; + str << nVector[i].has_mirror; + str << ","; + str << nVector[i].hidden; + str << ","; + str << nVector[i].amount; + str << ","; + str << nVector[i].angle; + str << ","; + str << nVector[i].steps; + if (i != nVector.size()-1) { + str << "@"; + } + } } StorageType readsvg(const gchar * str); diff --git a/src/live_effects/parameter/satellitearray.cpp b/src/live_effects/parameter/satellitearray.cpp deleted file mode 100644 index 1615f33e2..000000000 --- a/src/live_effects/parameter/satellitearray.cpp +++ /dev/null @@ -1,550 +0,0 @@ -/* - * Author(s): - * Jabiertxo Arraiza Cenoz - * - * Copyright (C) 2014 Author(s) - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "knotholder.h" -#include "ui/dialog/lpe-fillet-chamfer-properties.h" -#include "live_effects/parameter/satellitearray.h" -#include "live_effects/effect.h" -#include "sp-lpe-item.h" -#include -#include -// TODO due to internal breakage in glibmm headers, -// this has to be included last. -#include - -namespace Inkscape { - -namespace LivePathEffect { - -SatelliteArrayParam::SatelliteArrayParam(const Glib::ustring &label, - const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, - Effect *effect) - : ArrayParam(label, tip, key, wr, effect, 0), knoth(NULL) -{ - _knot_shape = SP_KNOT_SHAPE_DIAMOND; - _knot_mode = SP_KNOT_MODE_XOR; - _knot_color = 0xAAFF8800; - _helper_size = 0; - _use_distance = false; - _effectType = FILLET_CHAMFER; - _last_pointwise = NULL; -} - -void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, - SPKnotModeType mode, - guint32 color) -{ - _knot_shape = shape; - _knot_mode = mode; - _knot_color = color; -} - -void SatelliteArrayParam::setPointwise(Pointwise *pointwise) -{ - _last_pointwise = pointwise; - param_set_and_write_new_value(_last_pointwise->getSatellites()); -} - -void SatelliteArrayParam::setUseDistance(bool use_knot_distance) -{ - _use_distance = use_knot_distance; -} - -void SatelliteArrayParam::setEffectType(EffectType et) -{ - _effectType = et; -} - -void SatelliteArrayParam::setHelperSize(int hs) -{ - _helper_size = hs; - updateCanvasIndicators(); -} - -void SatelliteArrayParam::updateCanvasIndicators(bool mirror) -{ - if (!_last_pointwise) { - return; - } - - Geom::Piecewise > pwd2 = _last_pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - if (mirror == true) { - _hp.clear(); - } - for (size_t i = 0; i < _vector.size(); ++i) { - if (!_vector[i].active || _vector[i].hidden) { - continue; - } - if ((!_vector[i].has_mirror && mirror == true) || _vector[i].amount == 0) { - continue; - } - double pos = 0; - if (pwd2.size() <= i) { - break; - } - Geom::Curve *curve_in = pathv.curveAt(i).duplicate(); - bool overflow = false; - double size_out = _vector[i].arcDistance(*curve_in); - double lenght_out = curve_in->length(); - double lenght_in = 0; - - Geom::Path sat_path = pathv.pathAt(i); - boost::optional curve_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(i).initialPoint() , pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first) { - curve_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - curve_prev_index = sat_curve_time - 1; - } - if (curve_prev_index) { - lenght_in = pathv.curveAt(*curve_prev_index).length(); - } - if (mirror == true) { - if (curve_prev_index) { - curve_in = const_cast(&pathv.curveAt(*curve_prev_index)); - pos = _vector[i].time(size_out, true, *curve_in); - if (lenght_out < size_out) { - overflow = true; - } - } - } else { - pos = _vector[i].time(*curve_in); - if (lenght_in < size_out) { - overflow = true; - } - } - if (pos <= 0 || pos >= 1) { - continue; - } - Geom::Point point_a = curve_in->pointAt(pos); - Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos)); - Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); - deriv_a = deriv_a * rot; - Geom::Point point_c = point_a - deriv_a * _helper_size; - Geom::Point point_d = point_a + deriv_a * _helper_size; - Geom::Ray ray_1(point_c, point_d); - char const *svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - Geom::Affine aff = Geom::Affine(); - aff *= Geom::Scale(_helper_size); - if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); - } else { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); - } - aff *= Geom::Translate(curve_in->pointAt(pos)); - pathv *= aff; - _hp.push_back(pathv[0]); - _hp.push_back(pathv[1]); - if (overflow) { - double diameter = _helper_size; - if (_helper_size == 0) { - diameter = 15; - char const *svgd; - svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 " - "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - aff = Geom::Affine(); - aff *= Geom::Scale(diameter); - aff *= Geom::Translate(point_a - Geom::Point(diameter * 0.35, diameter * 0.35)); - pathv *= aff; - _hp.push_back(pathv[0]); - } else { - char const *svgd; - svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A " - "1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 " - "0 -1.32 z"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - aff = Geom::Affine(); - aff *= Geom::Scale(_helper_size / 2.0); - if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); - } else { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); - } - aff *= Geom::Translate(curve_in->pointAt(pos)); - pathv *= aff; - _hp.push_back(pathv[0]); - } - } - } - if (mirror == true) { - updateCanvasIndicators(false); - } -} -void SatelliteArrayParam::updateCanvasIndicators() -{ - updateCanvasIndicators(true); -} - -void SatelliteArrayParam::addCanvasIndicators( - SPLPEItem const */*lpeitem*/, std::vector &hp_vec) -{ - hp_vec.push_back(_hp); -} - -void SatelliteArrayParam::param_transform_multiply(Geom::Affine const &postmul, - bool /*set*/) -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - - if (prefs->getBool("/options/transform/rectcorners", true)) { - for (size_t i = 0; i < _vector.size(); ++i) { - if (!_vector[i].is_time && _vector[i].amount > 0) { - _vector[i].amount = _vector[i].amount * - ((postmul.expansionX() + postmul.expansionY()) / 2); - } - } - param_set_and_write_new_value(_vector); - } -} - -void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item, bool mirror) -{ - for (size_t i = 0; i < _vector.size(); ++i) { - size_t iPlus = i; - if (mirror == true) { - iPlus = i + _vector.size(); - } - if (!_vector[i].active) { - continue; - } - if (!_vector[i].has_mirror && mirror == true) { - continue; - } - using namespace Geom; - SatelliteType type = _vector[i].satellite_type; - //IF is for filletChamfer effect... - if (_effectType == FILLET_CHAMFER) { - const gchar *tip; - if (type == CHAMFER) { - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == INVERSE_CHAMFER) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == INVERSE_FILLET) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - FilletChamferKnotHolderEntity *e = - new FilletChamferKnotHolderEntity(this, iPlus); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - _knot_shape, _knot_mode, _knot_color); - knotholder->add(e); - } - } - if (mirror == true) { - addKnotHolderEntities(knotholder, desktop, item, false); - } -} - -void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item) -{ - knoth = knotholder; - addKnotHolderEntities(knotholder, desktop, item, true); -} - -FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( - SatelliteArrayParam *p, size_t index) - : _pparam(p), _index(index) {} - -void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, - Geom::Point const &/*origin*/, - guint state) -{ - Geom::Point s = snap_knot_position(p, state); - size_t index = _index; - if (_index >= _pparam->_vector.size()) { - index = _index - _pparam->_vector.size(); - } - if (!valid_index(index)) { - return; - } - - if (!_pparam->_last_pointwise) { - return; - } - - Satellite satellite = _pparam->_vector.at(index); - if (!satellite.active || satellite.hidden) { - return; - } - Pointwise *pointwise = _pparam->_last_pointwise; - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - if (_index >= _pparam->_vector.size() ) { - //I want to remplace this whith patvectorTime but need a way to know the index of a curve in a pathvector - //Geom::Path sat_path = pathv.pathAt(index); - //PathTime sat_time = sat_path.nearestTime(pathv.curveAt(index).initialPoint()); - //boost::optional previous_index = boost::none; - //if (sat_path.closed() && sat_time.curve_index == 0) { - // previous_index = sat_path.size(); - //} else if(!sat_path.closed() || sat_time.curve_index != 0) { - // previous_index = sat_time.curve_index - 1; - //} - //if (previous_index) { - Geom::Path sat_path = pathv.pathAt(index); - boost::optional curve_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first) { - curve_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - curve_prev_index = sat_curve_time - 1; - } - if (curve_prev_index) { - Geom::Curve const &curve_in = pathv.curveAt(*curve_prev_index); - double mirror_time = Geom::nearest_time(s, curve_in); - double time_start = 0; - std::vector sats = pointwise->getSatellites(); - time_start = sats[*curve_prev_index].time(curve_in); - if (time_start > mirror_time) { - mirror_time = time_start; - } - double size = arcLengthAt(mirror_time, curve_in); - double amount = curve_in.length() - size; - if (satellite.is_time) { - amount = timeAtArcLength(amount, pathv.curveAt(index)); - } - satellite.amount = amount; - } - } else { - satellite.setPosition(s, pathv.curveAt(index)); - } - _pparam->_vector.at(index) = satellite; - SPLPEItem *splpeitem = dynamic_cast(item); - if (splpeitem) { - sp_lpe_item_update_patheffect(splpeitem, false, false); - } -} - -Geom::Point FilletChamferKnotHolderEntity::knot_get() const -{ - Geom::Point tmp_point; - size_t index = _index; - if (_index >= _pparam->_vector.size()) { - index = _index - _pparam->_vector.size(); - } - if (!valid_index(index)) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - Satellite satellite = _pparam->_vector.at(index); - if (!_pparam->_last_pointwise) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - if (!satellite.active || satellite.hidden) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - Pointwise *pointwise = _pparam->_last_pointwise; - Geom::Piecewise > pwd2 = pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - if (pwd2.size() <= index) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - this->knot->show(); - if (_index >= _pparam->_vector.size()) { - tmp_point = satellite.getPosition(pathv.curveAt(index)); - Geom::Path sat_path = pathv.pathAt(index); - boost::optional curve_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint(), pwd2); - if (sat_path.closed() && sat_curve_time == first) { - curve_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - curve_prev_index = sat_curve_time - 1; - } - if (curve_prev_index) { - Geom::Curve const &curve_in = pathv.curveAt(*curve_prev_index); - double s = satellite.arcDistance(pathv.curveAt(index)); - double t = satellite.time(s, true, curve_in); - if (t > 1) { - t = 1; - } - if (t < 0) { - t = 0; - } - double time_start = 0; - time_start = pointwise->getSatellites()[*curve_prev_index].time(curve_in); - if (time_start > t) { - t = time_start; - } - tmp_point = (curve_in).pointAt(t); - } - } else { - tmp_point = satellite.getPosition(pathv.curveAt(index)); - } - Geom::Point const canvas_point = tmp_point; - return canvas_point; -} - -void FilletChamferKnotHolderEntity::knot_click(guint state) -{ - if (!_pparam->_last_pointwise) { - return; - } - - size_t index = _index; - if (_index >= _pparam->_vector.size()) { - index = _index - _pparam->_vector.size(); - } - if (state & GDK_CONTROL_MASK) { - if (state & GDK_MOD1_MASK) { - _pparam->_vector.at(index).amount = 0.0; - _pparam->param_set_and_write_new_value(_pparam->_vector); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - } else { - using namespace Geom; - SatelliteType type = _pparam->_vector.at(index).satellite_type; - switch (type) { - case FILLET: - type = INVERSE_FILLET; - break; - case INVERSE_FILLET: - type = CHAMFER; - break; - case CHAMFER: - type = INVERSE_CHAMFER; - break; - default: - type = FILLET; - break; - } - _pparam->_vector.at(index).satellite_type = type; - _pparam->param_set_and_write_new_value(_pparam->_vector); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); - const gchar *tip; - if (type == CHAMFER) { - tip = _("Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == INVERSE_CHAMFER) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else if (type == INVERSE_FILLET) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } else { - tip = _("Fillet: Ctrl+Click toggle type, " - "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); - } - this->knot->tip = g_strdup(tip); - this->knot->show(); - } - } else if (state & GDK_SHIFT_MASK) { - Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - double amount = _pparam->_vector.at(index).amount; - Geom::Path sat_path = pathv.pathAt(index); - boost::optional curve_prev_index = boost::none; - size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first) { - curve_prev_index = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - curve_prev_index = sat_curve_time - 1; - } - if (!_pparam->_use_distance && !_pparam->_vector.at(index).is_time) { - if (curve_prev_index) { - amount = _pparam->_vector.at(index).lenToRad(amount, pathv.curveAt(*curve_prev_index), pathv.curveAt(index), _pparam->_vector.at(*curve_prev_index)); - } else { - amount = 0.0; - } - } - bool aprox = false; - Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[index]; - if (curve_prev_index) { - Geom::D2 d2_in = - _pparam->_last_pointwise->getPwd2()[*curve_prev_index]; - aprox = ((d2_in)[0].degreesOfFreedom() != 2 || - d2_out[0].degreesOfFreedom() != 2) && - !_pparam->_use_distance - ? true - : false; - } - Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( - this->desktop, amount, this, _pparam->_use_distance, - aprox, _pparam->_vector.at(index)); - - } -} - -void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) -{ - if (!_pparam->_last_pointwise) { - return; - } - size_t index = _index; - if (_index >= _pparam->_vector.size()) { - index = _index - _pparam->_vector.size(); - } - double amount = satellite.amount; - double max_amount = amount; - if (!_pparam->_use_distance && !satellite.is_time) { - Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - Geom::Path sat_path = pathv.pathAt(index); - boost::optional prev = boost::none; - size_t sat_curve_time = Geom::nearest_time(pathv.curveAt(index).initialPoint(),pwd2); - size_t first = Geom::nearest_time(sat_path.initialPoint() , pwd2); - if (sat_path.closed() && sat_curve_time == first) { - prev = sat_curve_time + sat_path.size() - 1; - } else if(!sat_path.closed() || sat_curve_time != first) { - prev = sat_curve_time - 1; - } - if (prev) { - amount = _pparam->_vector.at(index).radToLen(amount, pathv.curveAt(*prev), pathv.curveAt(index)); - } else { - amount = 0.0; - } - if (max_amount > 0 && amount == 0) { - amount = _pparam->_vector.at(index).amount; - } - } - satellite.amount = amount; - _pparam->_vector.at(index) = satellite; - this->parent_holder->knot_ungrabbed_handler(this->knot, 0); - _pparam->param_set_and_write_new_value(_pparam->_vector); - SPLPEItem *splpeitem = dynamic_cast(item); - if (splpeitem) { - sp_lpe_item_update_patheffect(splpeitem, false, false); - } -} - -} /* namespace LivePathEffect */ - -} /* namespace Inkscape */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/satellitearray.h b/src/live_effects/parameter/satellitearray.h deleted file mode 100644 index bb8bf27c8..000000000 --- a/src/live_effects/parameter/satellitearray.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H -#define INKSCAPE_LIVEPATHEFFECT_SATELLITE_PAIR_ARRAY_H - -/* - * Inkscape::LivePathEffectParameters - * Copyright (C) Jabiertxo Arraiza Cenoz - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * To Nathan Hurst for his review and help on refactor - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * - * - * This parameter act as bridge from pointwise class to serialize it as a LPE - * parameter - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/parameter/array.h" -#include "live_effects/effect-enum.h" -#include "helper/geom-pointwise.h" -#include "knot-holder-entity.h" -#include - -namespace Inkscape { - -namespace LivePathEffect { - -class FilletChamferKnotHolderEntity; - -class SatelliteArrayParam : public ArrayParam { -public: - SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, Effect *effect); - - virtual Gtk::Widget *param_newWidget() - { - return NULL; - } - virtual void setHelperSize(int hs); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item, bool mirror); - virtual void addCanvasIndicators(SPLPEItem const *lpeitem, - std::vector &hp_vec); - virtual void updateCanvasIndicators(); - virtual void updateCanvasIndicators(bool mirror); - virtual bool providesKnotHolderEntities() const - { - return true; - } - void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); - void setUseDistance(bool use_knot_distance); - void setEffectType(EffectType et); - void setPointwise(Pointwise *pointwise); - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); - - friend class FilletChamferKnotHolderEntity; - friend class LPEFilletChamfer; - -protected: - KnotHolder *knoth; - -private: - SatelliteArrayParam(const SatelliteArrayParam &); - SatelliteArrayParam &operator=(const SatelliteArrayParam &); - - SPKnotShapeType _knot_shape; - SPKnotModeType _knot_mode; - guint32 _knot_color; - Geom::PathVector _hp; - int _helper_size; - bool _use_distance; - EffectType _effectType; - Pointwise *_last_pointwise; - -}; - -class FilletChamferKnotHolderEntity : public KnotHolderEntity { -public: - FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index); - virtual ~FilletChamferKnotHolderEntity() - { - _pparam->knoth = NULL; - } - - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, - guint state); - virtual Geom::Point knot_get() const; - virtual void knot_click(guint state); - void knot_set_offset(Satellite); - /** Checks whether the index falls within the size of the parameter's vector - */ - bool valid_index(size_t index) const - { - return (_pparam->_vector.size() > index); - } - ; - -private: - SatelliteArrayParam *_pparam; - size_t _index; -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp new file mode 100644 index 000000000..9274a4aff --- /dev/null +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -0,0 +1,527 @@ +/* + * Author(s): + * Jabiertxo Arraiza Cenoz + * + * Copyright (C) 2014 Author(s) + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "knotholder.h" +#include "ui/dialog/lpe-fillet-chamfer-properties.h" +#include "live_effects/parameter/satellitesarray.h" +#include "live_effects/effect.h" +#include "sp-lpe-item.h" +#include +#include +// TODO due to internal breakage in glibmm headers, +// this has to be included last. +#include + +namespace Inkscape { + +namespace LivePathEffect { + +SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, + const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, + Effect *effect) + : ArrayArrayParam >(label, tip, key, wr, effect, 0), knoth(NULL) +{ + _knot_shape = SP_KNOT_SHAPE_DIAMOND; + _knot_mode = SP_KNOT_MODE_XOR; + _knot_color = 0xAAFF8800; + _helper_size = 0; + _use_distance = false; + _effectType = FILLET_CHAMFER; + _last_pointwise = NULL; +} + +void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, + SPKnotModeType mode, + guint32 color) +{ + _knot_shape = shape; + _knot_mode = mode; + _knot_color = color; +} + +void SatellitesArrayParam::setPointwise(Pointwise *pointwise) +{ + _last_pointwise = pointwise; + param_set_and_write_new_value(_last_pointwise->getSatellites()); +} + +void SatellitesArrayParam::setUseDistance(bool use_knot_distance) +{ + _use_distance = use_knot_distance; +} + +void SatellitesArrayParam::setEffectType(EffectType et) +{ + _effectType = et; +} + +void SatellitesArrayParam::setHelperSize(int hs) +{ + _helper_size = hs; + updateCanvasIndicators(); +} + +void SatellitesArrayParam::updateCanvasIndicators(bool mirror) +{ + if (!_last_pointwise) { + return; + } + Geom::PathVector pathv = _last_pointwise->getPV(); + if (mirror == true) { + _hp.clear(); + } + for (size_t i = 0; i < _vector.size(); ++i) { + for (size_t j = 0; j < _vector[i].size(); ++j) { + if (!_vector[i][j].active || _vector[i][j].hidden) { + continue; + } + if ((!_vector[i][j].has_mirror && mirror == true) || _vector[i][j].amount == 0) { + continue; + } + double pos = 0; + if (pathv.size() <= i || pathv[i].size() <= j) { + break; + } + Geom::Curve *curve_in = pathv[i][j].duplicate(); + bool overflow = false; + double size_out = _vector[i][j].arcDistance(*curve_in); + double lenght_out = curve_in->length(); + double lenght_in = 0; + + boost::optional curve_prev_index = boost::none; + if(j == 0 && pathv[i].closed()){ + curve_prev_index = pathv[pathv[i].size() - 1]; + } else if(!pathv[i].closed() || j != 0) { + curve_prev_index = j - 1; + } + if (curve_prev_index) { + lenght_in = pathv.curveAt(*curve_prev_index).length(); + } + if (mirror == true) { + if (curve_prev_index) { + curve_in = const_cast(&pathv.curveAt(*curve_prev_index)); + pos = _vector[i][j].time(size_out, true, *curve_in); + if (lenght_out < size_out) { + overflow = true; + } + } + } else { + pos = _vector[i][j].time(*curve_in); + if (lenght_in < size_out) { + overflow = true; + } + } + if (pos <= 0 || pos >= 1) { + continue; + } + Geom::Point point_a = curve_in->pointAt(pos); + Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos)); + Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); + deriv_a = deriv_a * rot; + Geom::Point point_c = point_a - deriv_a * _helper_size; + Geom::Point point_d = point_a + deriv_a * _helper_size; + Geom::Ray ray_1(point_c, point_d); + char const *svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + Geom::Affine aff = Geom::Affine(); + aff *= Geom::Scale(_helper_size); + if (mirror == true) { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); + } else { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); + } + aff *= Geom::Translate(curve_in->pointAt(pos)); + pathv *= aff; + _hp.push_back(pathv[0]); + _hp.push_back(pathv[1]); + if (overflow) { + double diameter = _helper_size; + if (_helper_size == 0) { + diameter = 15; + char const *svgd; + svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 " + "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + aff = Geom::Affine(); + aff *= Geom::Scale(diameter); + aff *= Geom::Translate(point_a - Geom::Point(diameter * 0.35, diameter * 0.35)); + pathv *= aff; + _hp.push_back(pathv[0]); + } else { + char const *svgd; + svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A " + "1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 " + "0 -1.32 z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + aff = Geom::Affine(); + aff *= Geom::Scale(_helper_size / 2.0); + if (mirror == true) { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); + } else { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); + } + aff *= Geom::Translate(curve_in->pointAt(pos)); + pathv *= aff; + _hp.push_back(pathv[0]); + } + } + } + } + if (mirror == true) { + updateCanvasIndicators(false); + } +} +void SatellitesArrayParam::updateCanvasIndicators() +{ + updateCanvasIndicators(true); +} + +void SatellitesArrayParam::addCanvasIndicators( + SPLPEItem const */*lpeitem*/, std::vector &hp_vec) +{ + hp_vec.push_back(_hp); +} + +void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, + bool /*set*/) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + if (prefs->getBool("/options/transform/rectcorners", true)) { + for (size_t i = 0; i < _vector.size(); ++i) { + for (size_t j = 0; j < _vector[i].size(); ++j) { + if (!_vector[i][j].is_time && _vector[i][j].amount > 0) { + _vector[i][j].amount = _vector[i][j].amount * + ((postmul.expansionX() + postmul.expansionY()) / 2); + } + } + } + param_set_and_write_new_value(_vector); + } +} + +void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item, bool mirror) +{ + for (size_t i = 0; i < _vector.size(); ++i) { + for (size_t j = 0; j < _vector[i].size(); ++j) { + size_t iPlus = j; + if (mirror == true) { + iPlus = j + _vector[i].size(); + } + if (!_vector[i][j].active) { + continue; + } + if (!_vector[i][j].has_mirror && mirror == true) { + continue; + } + using namespace Geom; + SatelliteType type = _vector[i][j].satellite_type; + //IF is for filletChamfer effect... + if (_effectType == FILLET_CHAMFER) { + const gchar *tip; + if (type == CHAMFER) { + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == INVERSE_CHAMFER) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == INVERSE_FILLET) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } + FilletChamferKnotHolderEntity *e = + new FilletChamferKnotHolderEntity(this, i, iPlus); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + _knot_shape, _knot_mode, _knot_color); + knotholder->add(e); + } + } + } + if (mirror == true) { + addKnotHolderEntities(knotholder, desktop, item, false); + } +} + +void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item) +{ + knoth = knotholder; + addKnotHolderEntities(knotholder, desktop, item, true); +} + +FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( + SatellitesArrayParam *p, size_t index, size_t subindex) + : _pparam(p), _index(index), _subindex(subindex) {} + +void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, + Geom::Point const &/*origin*/, + guint state) +{ + Geom::Point s = snap_knot_position(p, state); + size_t subindex = _subindex; + if (_subindex >= _pparam->_vector[_index].size()) { + subindex = _subindex - _pparam->_vector[_index].size(); + } + if (!valid_index(subindex)) { + return; + } + + if (!_pparam->_last_pointwise) { + return; + } + + Satellite satellite = _pparam->_vector[_index].at(subindex); + if (!satellite.active || satellite.hidden) { + return; + } + Pointwise *pointwise = _pparam->_last_pointwise; + Geom::PathVector pathv = pparam->_last_pointwise->getPV(); + if (_subindex >= _pparam->_vector[_index].size() ) { + boost::optional curve_prev_index = boost::none; + if(_subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[pathv[_index].size() - 1]; + } else if(!pathv[_index].closed() || _subindex != 0) { + curve_prev_index = _subindex - 1; + } + if (curve_prev_index) { + Geom::Curve const &curve_in = pathv[_index][*curve_prev_index]; + double mirror_time = Geom::nearest_time(s, curve_in); + double time_start = 0; + Satellites sats = pointwise->getSatellites(); + time_start = sats[_index][*curve_prev_index].time(curve_in); + if (time_start > mirror_time) { + mirror_time = time_start; + } + double size = arcLengthAt(mirror_time, curve_in); + double amount = curve_in.length() - size; + if (satellite.is_time) { + amount = timeAtArcLength(amount, pathv[_index][); + } + satellite.amount = amount; + } + } else { + satellite.setPosition(s, pathv[_index]); + } + _pparam->_vector[_index][_subindex] = satellite; + SPLPEItem *splpeitem = dynamic_cast(item); + if (splpeitem) { + sp_lpe_item_update_patheffect(splpeitem, false, false); + } +} + +Geom::Point FilletChamferKnotHolderEntity::knot_get() const +{ + Geom::Point tmp_point; + size_t subindex = _subindex; + if (_subindex >= _pparam->_vector[_index].size()) { + subindex = _subindex - _pparam->_vector[_index].size(); + } + if (!valid_index(_subindex)) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } + Satellite satellite = _pparam->_vector[_index][_subindex]; + if (!_pparam->_last_pointwise) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } + if (!satellite.active || satellite.hidden) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } + Pointwise *pointwise = _pparam->_last_pointwise; + Geom::PathVector pathv = pparam->_last_pointwise->getPV(); + if (pathv[_index].size() <= subindex) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } + this->knot->show(); + if (_subindex >= _pparam->_vector[index].size()) { + tmp_point = satellite.getPosition(pathv[_index][_subindex]); + boost::optional curve_prev_index = boost::none; + if(_subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[pathv[_index].size() - 1]; + } else if(!pathv[_index].closed() || _subindex != 0) { + curve_prev_index = _subindex - 1; + } + if (curve_prev_index) { + Geom::Curve const &curve_in = pathv[_index][*curve_prev_index]; + double s = satellite.arcDistance(pathv[_index][_subindex]); + double t = satellite.time(s, true, curve_in); + if (t > 1) { + t = 1; + } + if (t < 0) { + t = 0; + } + double time_start = 0; + time_start = pointwise->getSatellites()[_index][*curve_prev_index].time(curve_in); + if (time_start > t) { + t = time_start; + } + tmp_point = (curve_in).pointAt(t); + } + } else { + tmp_point = satellite.getPosition(pathv[_index][_subindex]); + } + Geom::Point const canvas_point = tmp_point; + return canvas_point; +} + +void FilletChamferKnotHolderEntity::knot_click(guint state) +{ + if (!_pparam->_last_pointwise) { + return; + } + + size_t subindex = _subindex; + if (_subindex >= _pparam->_vector[_index].size()) { + subindex = _subindex - _pparam->_vector[_index].size(); + } + if (state & GDK_CONTROL_MASK) { + if (state & GDK_MOD1_MASK) { + _pparam->_vector[_index][_subindex].amount = 0.0; + _pparam->param_set_and_write_new_value(_pparam->_vector); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + } else { + using namespace Geom; + SatelliteType type = _pparam->_vector[_index][_subindex].satellite_type; + switch (type) { + case FILLET: + type = INVERSE_FILLET; + break; + case INVERSE_FILLET: + type = CHAMFER; + break; + case CHAMFER: + type = INVERSE_CHAMFER; + break; + default: + type = FILLET; + break; + } + _pparam->_vector[_index][subindex].satellite_type = type; + _pparam->param_set_and_write_new_value(_pparam->_vector); + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); + const gchar *tip; + if (type == CHAMFER) { + tip = _("Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == INVERSE_CHAMFER) { + tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else if (type == INVERSE_FILLET) { + tip = _("Inverse Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } else { + tip = _("Fillet: Ctrl+Click toggle type, " + "Shift+Click open dialog, " + "Ctrl+Alt+Click reset"); + } + this->knot->tip = g_strdup(tip); + this->knot->show(); + } + } else if (state & GDK_SHIFT_MASK) { + Geom::PathVector pathv = pparam->_last_pointwise->getPV(); + double amount = _pparam->_vector[_index][_subindex].amount; + boost::optional curve_prev_index = boost::none; + if(_subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[pathv[_index].size() - 1]; + } else if(!pathv[_index].closed() || _subindex != 0) { + curve_prev_index = _subindex - 1; + } + if (!_pparam->_use_distance && !_pparam->_vector[_index][subindex].is_time) { + if (curve_prev_index) { + amount = _pparam->_vector[_index][subindex].lenToRad(amount, pathv[_index][*curve_prev_index], pathv[_index][subindex], _pparam->_vector[_index][*curve_prev_index]); + } else { + amount = 0.0; + } + } + bool aprox = false; + Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[_index][subindex]; + if (curve_prev_index) { + Geom::D2 d2_in = + _pparam->_last_pointwise->getPwd2()[_index][*curve_prev_index]; + aprox = ((d2_in)[0].degreesOfFreedom() != 2 || + d2_out[0].degreesOfFreedom() != 2) && + !_pparam->_use_distance + ? true + : false; + } + Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( + this->desktop, amount, this, _pparam->_use_distance, + aprox, _pparam->_vector[_index][subindex]); + + } +} + +void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) +{ + if (!_pparam->_last_pointwise) { + return; + } + size_t subindex = _subindex; + if (_subindex >= _pparam->_vector[_index].size()) { + subindex = _subindex - _pparam->_vector[_index].size(); + } + double amount = satellite.amount; + double max_amount = amount; + if (!_pparam->_use_distance && !satellite.is_time) { + Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); + Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); + Geom::Path sat_path = pathv.pathAt(index); + boost::optional curve_prev_index = boost::none; + if(_subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[pathv[_index].size() - 1]; + } else if(!pathv[_index].closed() || _subindex != 0) { + curve_prev_index = _subindex - 1; + } + if (curve_prev_index) { + amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][*prev], pathv[_index][subindex]); + } else { + amount = 0.0; + } + if (max_amount > 0 && amount == 0) { + amount = _pparam->_vector[_index][subindex].amount; + } + } + satellite.amount = amount; + _pparam->_vector[_index][subindex] = satellite; + this->parent_holder->knot_ungrabbed_handler(this->knot, 0); + _pparam->param_set_and_write_new_value(_pparam->_vector); + SPLPEItem *splpeitem = dynamic_cast(item); + if (splpeitem) { + sp_lpe_item_update_patheffect(splpeitem, false, false); + } +} + +} /* namespace LivePathEffect */ + +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h new file mode 100644 index 000000000..db3776ba3 --- /dev/null +++ b/src/live_effects/parameter/satellitesarray.h @@ -0,0 +1,115 @@ +#ifndef INKSCAPE_LIVEPATHEFFECT_SATELLITES_ARRAY_H +#define INKSCAPE_LIVEPATHEFFECT_SATELLITES_ARRAY_H + +/* + * Inkscape::LivePathEffectParameters + * Copyright (C) Jabiertxo Arraiza Cenoz + * Special thanks to Johan Engelen for the base of the effect -powerstroke- + * Also to ScislaC for point me to the idea + * Also su_v for his construvtive feedback and time + * To Nathan Hurst for his review and help on refactor + * and finaly to Liam P. White for his big help on coding, that save me a lot of + * hours + * + * + * This parameter act as bridge from pointwise class to serialize it as a LPE + * parameter + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/array.h" +#include "live_effects/effect-enum.h" +#include "helper/geom-pointwise.h" +#include "knot-holder-entity.h" +#include + +namespace Inkscape { + +namespace LivePathEffect { + +class FilletChamferKnotHolderEntity; + +class SatellitesArrayParam : public ArrayArrayParam { +public: + SatellitesArrayParam(const Glib::ustring &label, const Glib::ustring &tip, + const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, Effect *effect); + + virtual Gtk::Widget *param_newWidget() + { + return NULL; + } + virtual void setHelperSize(int hs); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, + SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, + SPItem *item, bool mirror); + virtual void addCanvasIndicators(SPLPEItem const *lpeitem, + std::vector &hp_vec); + virtual void updateCanvasIndicators(); + virtual void updateCanvasIndicators(bool mirror); + virtual bool providesKnotHolderEntities() const + { + return true; + } + void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); + void setUseDistance(bool use_knot_distance); + void setEffectType(EffectType et); + void setPointwise(Pointwise *pointwise); + void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, + guint32 color); + + friend class FilletChamferKnotHolderEntity; + friend class LPEFilletChamfer; + +protected: + KnotHolder *knoth; + +private: + SatellitesArrayParam(const SatellitesArrayParam &); + SatellitesArrayParam &operator=(const SatellitesArrayParam &); + + SPKnotShapeType _knot_shape; + SPKnotModeType _knot_mode; + guint32 _knot_color; + Geom::PathVector _hp; + int _helper_size; + bool _use_distance; + EffectType _effectType; + Pointwise *_last_pointwise; + +}; + +class FilletChamferKnotHolderEntity : public KnotHolderEntity { +public: + FilletChamferKnotHolderEntity(SatellitesArrayParam *p, size_t index, size_t subindex); + virtual ~FilletChamferKnotHolderEntity() + { + _pparam->knoth = NULL; + } + + virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, + guint state); + virtual Geom::Point knot_get() const; + virtual void knot_click(guint state); + void knot_set_offset(Satellite); + /** Checks whether the index falls within the size of the parameter's vector + */ + bool valid_index(size_t index) const + { + return (_pparam->_vector.size() > index); + } + ; + +private: + SatellitesArrayParam *_pparam; + size_t _index; + size_t _subindex; +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif -- cgit v1.2.3 From 07717a370b8efe6ddbb0c69d115bb063a2e7686a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 10 May 2016 23:16:49 +0200 Subject: Working with path updates (bzr r13645.1.130) --- src/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 +- src/live_effects/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(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index a96b7cbda..a7082ec24 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 4c2ec7957..fa03a5db7 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 027497d78..2672a571b 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 a1aa811a9..64364c88c 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -65,7 +65,7 @@ set(live_effects_SRC parameter/path.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp - parameter/satellitearray.cpp + parameter/satellitesarray.cpp parameter/random.cpp parameter/text.cpp parameter/togglebutton.cpp @@ -145,7 +145,7 @@ set(live_effects_SRC parameter/path.h parameter/point.h parameter/powerstrokepointarray.h - parameter/satellitearray.h + parameter/satellitesarray.h parameter/random.h parameter/text.h parameter/togglebutton.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index bcab1c055..ab1cf41e3 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -97,29 +97,32 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) continue; } std::vector subpath_satellites; - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - bool start = true; - while (curve_it1 != curve_endit) { - bool hidden = false; - if (start) { - if (!path_it->closed()) { - hidden = true; - } - start = false; - } + for (Geom::Path::const_iterator curve_it = path_it->begin(); curve_it != path_it->end(); ++curve_it) { + //Maybe we want this satellites... + //if (curve_it->isDegenerate()) { + // continue + //} + Satellite satellite(FILLET); + satellite.setSteps(chamfer_steps); + subpath_satellites.push_back(satellite); + } + //we add the last satellite on open path because pointwise is related to nodes, not curves + //so maybe in the future we can need this last satellite in other effects + //dont remove for this effect because pointwise class has methods when the path is modiffied + //and we want one method for all uses + if (!path_it->closed()) { Satellite satellite(FILLET); - satellite.setHidden(hidden); satellite.setSteps(chamfer_steps); subpath_satellites.push_back(satellite); - ++curve_it1; } satellites.push_back(subpath_satellites); } pointwise = new Pointwise(); + //Why Pwd2? Could we switch all to pathvector instead? + //I usualy use a pathvector, except some curve operations with D2 + //if yes maybe "poinwise" need a rename pointwise->setPwd2(paths_to_pw(pathv)); pointwise->setSatellites(satellites); - //pointwise->setStart(); satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -261,29 +264,33 @@ void LPEFilletChamfer::updateAmount() for (size_t j = 0; j < satellites[i].size(); ++j) { boost::optional curve_prev_index = boost::none; if(j == 0 && pathv[i].closed()){ - curve_prev_index = pathv[pathv[i].size() - 1]; + curve_prev_index = pathv[i].size() - 1; } else if(!pathv[i].closed() || j != 0) { curve_prev_index = j - 1; } - if (!pathv[i].closed() && sat_curve_time == 0) { - it->amount = 0; + if (!pathv[i].closed() && j == 0) { + satellites[i][j].amount = 0; + continue; + } + if (pathv[i].size() == j) { continue; } - if ((!apply_no_radius && it->amount == 0) || - (!apply_with_radius && it->amount != 0)) + if ((!apply_no_radius && satellites[i][j].amount == 0) || + (!apply_with_radius && satellites[i][j].amount != 0)) { continue; } - Geom::Point satellite_point = pwd2.valueAt(it - satellites.begin()); + + Geom::Point satellite_point = pathv[i].pointAt(j); if (isNodePointSelected(satellite_point) || !only_selected) { if (!use_knot_distance && !flexible) { if(curve_prev_index) { - it->amount = it->radToLen(power, pathv[i][*curve_prev_index], pathv[i][j]); + satellites[i][j].amount = satellites[i][j].radToLen(power, pathv[i][*curve_prev_index], pathv[i][j]); } else { - it->amount = 0.0; + satellites[i][j].amount = 0.0; } } else { - it->amount = power; + satellites[i][j].amount = power; } } } @@ -294,22 +301,22 @@ void LPEFilletChamfer::updateAmount() void LPEFilletChamfer::updateChamferSteps() { - std::vector satellites = pointwise->getSatellites(); + Satellites satellites = pointwise->getSatellites(); Geom::PathVector pathv = pointwise->getPV(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { - if ((!apply_no_radius && satellites[i][j]->amount == 0) || - (!apply_with_radius && satellites[i][j]->amount != 0)) + if ((!apply_no_radius && satellites[i][j].amount == 0) || + (!apply_with_radius && satellites[i][j].amount != 0)) { continue; } if (only_selected) { Geom::Point satellite_point = pathv[i].pointAt(j); if (isNodePointSelected(satellite_point)) { - satellites[i][j]->steps = chamfer_steps; + satellites[i][j].steps = chamfer_steps; } } else { - satellites[i][j]->steps = chamfer_steps; + satellites[i][j].steps = chamfer_steps; } } } @@ -319,22 +326,28 @@ void LPEFilletChamfer::updateChamferSteps() void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - std::vector satellites = pointwise->getSatellites(); + Satellites satellites = pointwise->getSatellites(); Geom::PathVector pathv = pointwise->getPV(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { - if ((!apply_no_radius && satellites[i][j]->amount == 0) || - (!apply_with_radius && satellites[i][j]->amount != 0)) + if ((!apply_no_radius && satellites[i][j].amount == 0) || + (!apply_with_radius && satellites[i][j].amount != 0)) { continue; } + if (pathv[i].size() == j) { + if (!only_selected) { + satellites[i][j].satellite_type = satellitetype; + } + continue; + } if (only_selected) { Geom::Point satellite_point = pathv[i].pointAt(j); if (isNodePointSelected(satellite_point)) { - satellites[i][j]->satellite_type = satellitetype; + satellites[i][j].satellite_type = satellitetype; } } else { - satellites[i][j]->satellite_type = satellitetype; + satellites[i][j].satellite_type = satellitetype; } } } @@ -361,44 +374,47 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites_param.setEffectType(effectType()); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Geom::Piecewise > pwd2 = paths_to_pw(pathv); - pwd2 = remove_short_cuts(pwd2, 0.01); - Satellites satelites = satellites_param.data(); - if(satelites.empty()) { + Geom::Piecewise > pwd2 = remove_short_cuts(paths_to_pw(pathv), 0.01);; + Satellites satellites = satellites_param.data(); + if(satellites.empty()) { doOnApply(lpeItem); - satelites = satellites_param.data(); + satellites = satellites_param.data(); } if (hide_knots) { satellites_param.setHelperSize(0); } else { satellites_param.setHelperSize(helper_size); } - size_t number_curves = pathv.curveCount(); + size_t number_nodes = pathv.nodes().size(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { - if (satellites[i][j]->is_time != flexible) { - satellites[i][j]->is_time = flexible; - double amount = satellites[i][j]->amount; + if (satellites[i][j].is_time != flexible) { + satellites[i][j].is_time = flexible; + double amount = satellites[i][j].amount; + if (pathv[i].size() == j){ + continue; + } Geom::Curve const &curve_in = pathv[i][j]; - if (satellites[i][j]->is_time) { + if (satellites[i][j].is_time) { double time = timeAtArcLength(amount, curve_in); - satellites[i][j]->amount = time; + satellites[i][j].amount = time; } else { double size = arcLengthAt(amount, curve_in); - satellites[i][j]->amount = size; + satellites[i][j].amount = size; } } - if (satellites[i][j]->has_mirror != mirror_knots) { - satellites[i][j]->has_mirror = mirror_knots; + if (satellites[i][j].has_mirror != mirror_knots) { + satellites[i][j].has_mirror = mirror_knots; } - satellites[i][j]->hidden = hide_knots; + satellites[i][j].hidden = hide_knots; } } //if are diferent sizes call to poinwise recalculate //todo: fire a reverse satellites on reverse path. Maybe a new method //like "are_similar" to avoid precission issues on reverse a pointwise //and after convert to Pathvector - if (pointwise && number_curves != pointwise->getTotalSatellites()) { + if (pointwise && number_nodes != pointwise->getTotalSatellites()) { + std::cout << "gasdfgffffffffffffffffffffffffffffffffffffffffffffffffff\n"; Satellite satellite(satellites[0][0].satellite_type); satellite.setIsTime(satellites[0][0].is_time); satellite.setHasMirror(satellites[0][0].has_mirror); @@ -408,7 +424,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise->setPwd2(pwd2); pointwise->setSatellites(satellites); } - pointwise->setStart(); satellites_param.setPointwise(pointwise); refreshKnots(); } else { @@ -427,86 +442,63 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) { const double GAP_HELPER = 0.00001; Geom::PathVector path_out; - size_t counter_paths = 0; + size_t path = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - Geom::PathVector path_in_processed = pathv_to_linear_and_cubic_beziers(path_in); - for (Geom::PathVector::const_iterator path_it = path_in_processed.begin(); path_it != path_in_processed.end(); ++path_it) { + Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); + for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { if (path_it->empty()) { continue; } _hp.push_back(*path_it); Geom::Path tmp_path; - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); if (path_it->size() == 1) { - counter++; - tmp_path.start((*curve_it1).pointAt(0)); - tmp_path.append(*curve_it1); + path++; + tmp_path.start(path_it[0].pointAt(0)); + tmp_path.append(path_it[0]); path_out.push_back(tmp_path); continue; } - size_t counter_curves = 0; - size_t first = counter; double time0 = 0; - Satellites satelites = pointwise->getSatellites(); - while (curve_it1 != curve_endit) { - if (curve_it2 != curve_endit && (*curve_it2).isDegenerate()) { - ++curve_it2; - } - if ((*curve_it1).isDegenerate()) { - ++curve_it1; - counter_curves++; - time0 = 0.0; - continue; - } - Satellite satellite; - Geom::Curve *curve_it2_fixed = path_it->begin()->duplicate(); - if (!path_it->closed()) { - if (curve_it2 != curve_endit) { - curve_it2_fixed = (*curve_it2).duplicate(); - if (satellites[counter_paths].size() > counter_curves + 1) { - satellite = satellites[counter_paths][counter_curves + 1]; - } - } else { - if (time0 != 1) { - Geom::Curve *last_curve = curve_it1->portion(time0, 1); - last_curve->setInitial(tmp_path.finalPoint()); - tmp_path.append(*last_curve); - } - ++curve_it1; - counter_curves++; - continue; - } - } else { - if (curve_it2 != curve_endit) { - curve_it2_fixed = (*curve_it2).duplicate(); - if (satellites[counter_paths].size() > counter_curves + 1) { - satellite = satellites[counter_paths][counter_curves + 1];; - } - - } else { - if (satellites[counter_paths].size() > 0) { - satellite = satellites[counter_paths][0]; - } + size_t curve = 0; + Satellites satellites = pointwise->getSatellites(); + for (Geom::Path::const_iterator curve_it1 = path_it->begin(); curve_it1 != path_it->end(); ++curve_it1) { + boost::optional curve_next_index = boost::none; + if (curve == pathv[path].size() - 1 && pathv[path].closed()) { + curve_next_index = 0; + } else if (curve != pathv[path].size() -1 || !pathv[path].closed()) { + curve_next_index = curve + 1; + } + if (curve == pathv[path].size() -1 && !pathv[path].closed()) { //the path is open and we are at end of path + if (time0 != 1) { //Previous satellite not at 100% amount + Geom::Curve *last_curve = curve_it1->portion(time0, 1); + last_curve->setInitial(tmp_path.finalPoint()); + tmp_path.append(*last_curve); + delete last_curve; } + continue; } - if (counter_curves == 0) { - if (satellites[counter_paths].size() > 0 && satellites[counter_paths][0].active) { - time0 = satellites[counter_paths][0].time(*path_it->begin()); - } else { + Geom::Curve const &curve_it2 = pathv[path][*curve_next_index]; +// if (curve != pathv[path].size() && (*curve_it2).isDegenerate()) { +// ++curve_it2; +// } +// if ((*curve_it1).isDegenerate()) { +// ++curve_it1; +// counter_curves++; +// time0 = 0.0; +// continue; +// } + Satellite satellite = satellites[path][*curve_next_index]; + if (!curve) { //curve == 0 + if (!path_it->closed()) { time0 = 0; + } else { + time0 = satellites[path][0].time(*curve_it1); } } - Geom::Curve const &curve_it2_fixed_ref = *curve_it2_fixed; - bool last = curve_it2 == curve_endit; - double s = satellite.arcDistance(curve_it2_fixed_ref); + bool last = pathv[path].size() - 1 == curve; + double s = satellite.arcDistance(curve_it2); double time1 = satellite.time(s, true, (*curve_it1)); - double time2 = satellite.time(curve_it2_fixed_ref); - if (!satellite.active) { - time1 = 1; - time2 = 0; - } + double time2 = satellite.time(curve_it2); if (time1 <= time0) { time1 = time0; @@ -519,22 +511,22 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) times.push_back(time1); times.push_back(time2); Geom::Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); - if (counter_curves > 0) { + if (curve > 0) { knot_curve_1->setInitial(tmp_path.finalPoint()); } else { tmp_path.start((*curve_it1).pointAt(times[0])); } Geom::Point start_arc_point = knot_curve_1->finalPoint(); - Geom::Point end_arc_point = curve_it2_fixed_ref.pointAt(times[2]); + Geom::Point end_arc_point = curve_it2.pointAt(times[2]); if (times[2] == 1) { - end_arc_point = curve_it2_fixed_ref.pointAt(times[2] - GAP_HELPER); + end_arc_point = curve_it2.pointAt(times[2] - GAP_HELPER); } if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0] + GAP_HELPER); } double k1 = distance(start_arc_point, curve_it1->finalPoint()) * K; - double k2 = distance(end_arc_point, curve_it2_fixed_ref.initialPoint()) * K; + double k2 = distance(end_arc_point, curve_it2.initialPoint()) * K; Geom::CubicBezier const *cubic_1 = dynamic_cast(&*knot_curve_1); Geom::Ray ray_1(start_arc_point, curve_it1->finalPoint()); @@ -545,10 +537,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (time0 == 1) { handle_1 = start_arc_point; } - Geom::Curve *knot_curve_2 = curve_it2_fixed_ref.portion(times[2], 1); + Geom::Curve *knot_curve_2 = curve_it2.portion(times[2], 1); Geom::CubicBezier const *cubic_2 = dynamic_cast(&*knot_curve_2); - Geom::Ray ray_2(curve_it2_fixed_ref.initialPoint(), end_arc_point); + Geom::Ray ray_2(curve_it2.initialPoint(), end_arc_point); if (cubic_2) { ray_2.setPoints(end_arc_point, (*cubic_2)[1]); } @@ -571,7 +563,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } Geom::Point inverse_handle_2 = end_arc_point - Geom::Point::polar(handleAngle, k2); if (times[2] == 1) { - end_arc_point = curve_it2_fixed_ref.pointAt(times[2]); + end_arc_point = curve_it2.pointAt(times[2]); } if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0]); @@ -599,7 +591,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || + is_straight_curve(curve_it2) && method != FM_BEZIER) || method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; path_chamfer.appendNew(rx, ry, arc_angle, 0, @@ -618,7 +610,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || + is_straight_curve(curve_it2) && method != FM_BEZIER) || method == FM_ARC) { path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); @@ -635,7 +627,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) tmp_path.appendNew(end_arc_point); } else if (type == INVERSE_FILLET) { if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || + is_straight_curve(curve_it2) && method != FM_BEZIER) || method == FM_ARC) { tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); @@ -645,7 +637,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } } else if (type == FILLET) { if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2_fixed_ref) && method != FM_BEZIER) || + is_straight_curve(curve_it2) && method != FM_BEZIER) || method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, @@ -663,14 +655,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (path_it->closed() && last) { tmp_path.close(); } - ++curve_it1; - if (curve_it2 != curve_endit) { - ++curve_it2; - } - counter_curves++; + curve++; time0 = times[2]; } - counter_paths++; + path++; path_out.push_back(tmp_path); } return path_out; diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 0bbe39293..c9e2d6563 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -15,35 +15,36 @@ namespace LivePathEffect { //TODO: move maybe unsigned int -sp_svg_satellite_vector_read_d(gchar const *str, std::vector *satellites){ +sp_svg_satellite_vector_read_d(gchar const *str, std::vector *subpath_satellites){ if (!str) { return 0; } - gchar ** strarray = g_strsplit(str, "@", 0); - for (size_t i = 0; i < strarray.size(); ++i) { - gchar ** strsubarray = g_strsplit(strarray[i], ",", 7); + gchar ** strarray = g_strsplit(str, " @ ", 0); + gchar ** iter = strarray; + while (*iter != NULL) { + gchar ** strsubarray = g_strsplit(*iter, ",", 7); if(strlen(str) > 0 && strsubarray[6] && !strsubarray[7]){ - Satellite sat; - sat->setSatelliteType(g_strstrip(strsubarray[0])); - sat->is_time = strncmp(strsubarray[1],"1",1) == 0; - sat->has_mirror = strncmp(strsubarray[2],"1",1) == 0; - sat->hidden = strncmp(strsubarray[3],"1",1) == 0; + Satellite satellite; + satellite.setSatelliteType(g_strstrip(strsubarray[0])); + satellite.is_time = strncmp(strsubarray[1],"1",1) == 0; + satellite.has_mirror = strncmp(strsubarray[2],"1",1) == 0; + satellite.hidden = strncmp(strsubarray[3],"1",1) == 0; double amount,angle; float stepsTmp; sp_svg_number_read_d(strsubarray[4], &amount); sp_svg_number_read_d(strsubarray[5], &angle); sp_svg_number_read_f(strsubarray[6], &stepsTmp); unsigned int steps = (unsigned int)stepsTmp; - sat->amount = amount; - sat->angle = angle; - sat->steps = steps; + satellite.amount = amount; + satellite.angle = angle; + satellite.steps = steps; + subpath_satellites->push_back(satellite); g_strfreev (strsubarray); - satellites.push_back(sat); } - g_strfreev (strsubarray); + iter++; } g_strfreev (strarray); - if (!sat.empty()){ + if (!subpath_satellites->empty()){ return 1; } return 0; @@ -88,12 +89,12 @@ template <> std::vector ArrayParam >::readsvg(const gchar * str) { - std::vector satellites; - if (sp_svg_satellite_vector_read_d(str, &satellites)) { - return satellites; + std::vector subpath_satellites; + if (sp_svg_satellite_vector_read_d(str, &subpath_satellites)) { + return subpath_satellites; } - satellites.push_back(Satellite satellite(FILLET)); - return satellites; + subpath_satellites.push_back(Satellite(FILLET)); + return subpath_satellites; } diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 7076a465f..64d01650c 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -51,7 +51,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue) { _vector.clear(); - gchar ** strarray = g_strsplit(strvalue, "|", 0); + gchar ** strarray = g_strsplit(strvalue, " | ", 0); gchar ** iter = strarray; while (*iter != NULL) { _vector.push_back( readsvg(*iter) ); @@ -112,6 +112,10 @@ protected: void writesvgData(SVGOStringStream &str, std::vector const &nVector) const { for (size_t i = 0; i < nVector.size(); ++i) { + if (i != 0) { + // separate items with @ symbol ¿Any other? + str << " @ "; + } str << nVector[i].getSatelliteTypeGchar(); str << ","; str << nVector[i].is_time; @@ -125,9 +129,6 @@ protected: str << nVector[i].angle; str << ","; str << nVector[i].steps; - if (i != nVector.size()-1) { - str << "@"; - } } } diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 9274a4aff..9f14a1d5b 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -26,7 +26,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayArrayParam >(label, tip, key, wr, effect, 0), knoth(NULL) + : ArrayParam >(label, tip, key, wr, effect, 0), knoth(NULL) { _knot_shape = SP_KNOT_SHAPE_DIAMOND; _knot_mode = SP_KNOT_MODE_XOR; @@ -77,104 +77,106 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) if (mirror == true) { _hp.clear(); } - for (size_t i = 0; i < _vector.size(); ++i) { - for (size_t j = 0; j < _vector[i].size(); ++j) { - if (!_vector[i][j].active || _vector[i][j].hidden) { - continue; - } - if ((!_vector[i][j].has_mirror && mirror == true) || _vector[i][j].amount == 0) { - continue; - } - double pos = 0; - if (pathv.size() <= i || pathv[i].size() <= j) { - break; - } - Geom::Curve *curve_in = pathv[i][j].duplicate(); - bool overflow = false; - double size_out = _vector[i][j].arcDistance(*curve_in); - double lenght_out = curve_in->length(); - double lenght_in = 0; - - boost::optional curve_prev_index = boost::none; - if(j == 0 && pathv[i].closed()){ - curve_prev_index = pathv[pathv[i].size() - 1]; - } else if(!pathv[i].closed() || j != 0) { - curve_prev_index = j - 1; - } - if (curve_prev_index) { - lenght_in = pathv.curveAt(*curve_prev_index).length(); - } - if (mirror == true) { + if (_effectType == FILLET_CHAMFER) { + for (size_t i = 0; i < _vector.size(); ++i) { + for (size_t j = 0; j < _vector[i].size(); ++j) { + if ( _vector[i][j].hidden) { + continue; + } + if ((!_vector[i][j].has_mirror && mirror == true) || _vector[i][j].amount == 0) { + continue; + } + double pos = 0; + if (pathv[i].size() == j) { //ignore last satellite in open paths with fillet chamfer effect + continue; + } + Geom::Curve *curve_in = pathv[i][j].duplicate(); + bool overflow = false; + double size_out = _vector[i][j].arcDistance(*curve_in); + double lenght_out = curve_in->length(); + double lenght_in = 0; + + boost::optional curve_prev_index = boost::none; + if(j == 0 && pathv[i].closed()){ + curve_prev_index = pathv[i].size() - 1; + } else if(!pathv[i].closed() || j != 0) { + curve_prev_index = j - 1; + } if (curve_prev_index) { - curve_in = const_cast(&pathv.curveAt(*curve_prev_index)); - pos = _vector[i][j].time(size_out, true, *curve_in); - if (lenght_out < size_out) { + lenght_in = pathv.curveAt(*curve_prev_index).length(); + } + if (mirror) { + if (curve_prev_index) { + curve_in = const_cast(&pathv.curveAt(*curve_prev_index)); + pos = _vector[i][j].time(size_out, true, *curve_in); + if (lenght_out < size_out) { + overflow = true; + } + } + } else { + pos = _vector[i][j].time(*curve_in); + if (lenght_in < size_out) { overflow = true; } } - } else { - pos = _vector[i][j].time(*curve_in); - if (lenght_in < size_out) { - overflow = true; + if (pos <= 0 || pos >= 1) { + continue; } - } - if (pos <= 0 || pos >= 1) { - continue; - } - Geom::Point point_a = curve_in->pointAt(pos); - Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos)); - Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); - deriv_a = deriv_a * rot; - Geom::Point point_c = point_a - deriv_a * _helper_size; - Geom::Point point_d = point_a + deriv_a * _helper_size; - Geom::Ray ray_1(point_c, point_d); - char const *svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - Geom::Affine aff = Geom::Affine(); - aff *= Geom::Scale(_helper_size); - if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); - } else { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); - } - aff *= Geom::Translate(curve_in->pointAt(pos)); - pathv *= aff; - _hp.push_back(pathv[0]); - _hp.push_back(pathv[1]); - if (overflow) { - double diameter = _helper_size; - if (_helper_size == 0) { - diameter = 15; - char const *svgd; - svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 " - "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - aff = Geom::Affine(); - aff *= Geom::Scale(diameter); - aff *= Geom::Translate(point_a - Geom::Point(diameter * 0.35, diameter * 0.35)); - pathv *= aff; - _hp.push_back(pathv[0]); + Geom::Point point_a = curve_in->pointAt(pos); + Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos)); + Geom::Rotate rot(Geom::Rotate::from_degrees(-90)); + deriv_a = deriv_a * rot; + Geom::Point point_c = point_a - deriv_a * _helper_size; + Geom::Point point_d = point_a + deriv_a * _helper_size; + Geom::Ray ray_1(point_c, point_d); + char const *svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + Geom::Affine aff = Geom::Affine(); + aff *= Geom::Scale(_helper_size); + if (mirror) { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); } else { - char const *svgd; - svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A " - "1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 " - "0 -1.32 z"; - Geom::PathVector pathv = sp_svg_read_pathv(svgd); - aff = Geom::Affine(); - aff *= Geom::Scale(_helper_size / 2.0); - if (mirror == true) { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); + } + aff *= Geom::Translate(curve_in->pointAt(pos)); + pathv *= aff; + _hp.push_back(pathv[0]); + _hp.push_back(pathv[1]); + if (overflow) { + double diameter = _helper_size; + if (_helper_size == 0) { + diameter = 15; + char const *svgd; + svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 " + "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + aff = Geom::Affine(); + aff *= Geom::Scale(diameter); + aff *= Geom::Translate(point_a - Geom::Point(diameter * 0.35, diameter * 0.35)); + pathv *= aff; + _hp.push_back(pathv[0]); } else { - aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); + char const *svgd; + svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A " + "1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 " + "0 -1.32 z"; + Geom::PathVector pathv = sp_svg_read_pathv(svgd); + aff = Geom::Affine(); + aff *= Geom::Scale(_helper_size / 2.0); + if (mirror) { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90)); + } else { + aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270)); + } + aff *= Geom::Translate(curve_in->pointAt(pos)); + pathv *= aff; + _hp.push_back(pathv[0]); } - aff *= Geom::Translate(curve_in->pointAt(pos)); - pathv *= aff; - _hp.push_back(pathv[0]); } } } } - if (mirror == true) { + if (mirror) { updateCanvasIndicators(false); } } @@ -198,8 +200,7 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { if (!_vector[i][j].is_time && _vector[i][j].amount > 0) { - _vector[i][j].amount = _vector[i][j].amount * - ((postmul.expansionX() + postmul.expansionY()) / 2); + _vector[i][j].amount = _vector[i][j].amount * ((postmul.expansionX() + postmul.expansionY()) / 2); } } } @@ -208,24 +209,22 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, } void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item, bool mirror) + SPDesktop *desktop, + SPItem *item, bool mirror) { for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { - size_t iPlus = j; - if (mirror == true) { - iPlus = j + _vector[i].size(); - } - if (!_vector[i][j].active) { + if (!_vector[i][j].has_mirror && mirror) { continue; } - if (!_vector[i][j].has_mirror && mirror == true) { - continue; + SatelliteType type = _vector[i][j].satellite_type; + size_t index = i; + size_t subindex = j; + if (mirror) { + subindex = subindex + _vector[i].size(); } using namespace Geom; - SatelliteType type = _vector[i][j].satellite_type; - //IF is for filletChamfer effect... + //If is for filletChamfer effect... if (_effectType == FILLET_CHAMFER) { const gchar *tip; if (type == CHAMFER) { @@ -245,15 +244,13 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } - FilletChamferKnotHolderEntity *e = - new FilletChamferKnotHolderEntity(this, i, iPlus); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - _knot_shape, _knot_mode, _knot_color); + FilletChamferKnotHolderEntity *e = new FilletChamferKnotHolderEntity(this, index, subindex); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip),_knot_shape, _knot_mode, _knot_color); knotholder->add(e); } } } - if (mirror == true) { + if (mirror) { addKnotHolderEntities(knotholder, desktop, item, false); } } @@ -279,7 +276,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } - if (!valid_index(subindex)) { + if (!valid_index(_index)) { return; } @@ -287,39 +284,39 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, return; } - Satellite satellite = _pparam->_vector[_index].at(subindex); - if (!satellite.active || satellite.hidden) { + Satellite satellite = _pparam->_vector[_index][subindex]; + if (satellite.hidden) { return; } Pointwise *pointwise = _pparam->_last_pointwise; - Geom::PathVector pathv = pparam->_last_pointwise->getPV(); - if (_subindex >= _pparam->_vector[_index].size() ) { + Geom::PathVector pathv = pointwise->getPV(); + if (subindex != _subindex) { boost::optional curve_prev_index = boost::none; - if(_subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[pathv[_index].size() - 1]; - } else if(!pathv[_index].closed() || _subindex != 0) { - curve_prev_index = _subindex - 1; + if(subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[_index].size() - 1; + } else if(!pathv[_index].closed() || subindex != 0) { + curve_prev_index = subindex - 1; } if (curve_prev_index) { Geom::Curve const &curve_in = pathv[_index][*curve_prev_index]; double mirror_time = Geom::nearest_time(s, curve_in); double time_start = 0; - Satellites sats = pointwise->getSatellites(); - time_start = sats[_index][*curve_prev_index].time(curve_in); + Satellites satellites = pointwise->getSatellites(); + time_start = satellites[_index][*curve_prev_index].time(curve_in); if (time_start > mirror_time) { mirror_time = time_start; } double size = arcLengthAt(mirror_time, curve_in); double amount = curve_in.length() - size; if (satellite.is_time) { - amount = timeAtArcLength(amount, pathv[_index][); + amount = timeAtArcLength(amount, pathv[_index][subindex]); } satellite.amount = amount; } } else { - satellite.setPosition(s, pathv[_index]); + satellite.setPosition(s, pathv[_index][subindex]); } - _pparam->_vector[_index][_subindex] = satellite; + _pparam->_vector[_index][subindex] = satellite; SPLPEItem *splpeitem = dynamic_cast(item); if (splpeitem) { sp_lpe_item_update_patheffect(splpeitem, false, false); @@ -333,33 +330,41 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } - if (!valid_index(_subindex)) { + if (!valid_index(_index)) { return Geom::Point(Geom::infinity(), Geom::infinity()); } - Satellite satellite = _pparam->_vector[_index][_subindex]; - if (!_pparam->_last_pointwise) { + Satellite satellite = _pparam->_vector[_index][subindex]; + Pointwise *pointwise = _pparam->_last_pointwise; + if (!pointwise) { return Geom::Point(Geom::infinity(), Geom::infinity()); } - if (!satellite.active || satellite.hidden) { + Geom::PathVector pathv = pointwise->getPV(); + if (pathv[_index].size() <= subindex){ //We know this path is open and is last satellite. Hide it + _pparam->_vector[_index][subindex].hidden = true; return Geom::Point(Geom::infinity(), Geom::infinity()); } - Pointwise *pointwise = _pparam->_last_pointwise; - Geom::PathVector pathv = pparam->_last_pointwise->getPV(); - if (pathv[_index].size() <= subindex) { + if (!pathv[_index].closed() && subindex == 0){ //Path is open hide first satellite + _pparam->_vector[_index][subindex].hidden = true; + return Geom::Point(Geom::infinity(), Geom::infinity()); + } + if (satellite.hidden) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } + if (subindex != _subindex && !_pparam->_vector[_index][subindex].has_mirror) { return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); - if (_subindex >= _pparam->_vector[index].size()) { - tmp_point = satellite.getPosition(pathv[_index][_subindex]); + if (subindex != _subindex) { + tmp_point = satellite.getPosition(pathv[_index][subindex]); boost::optional curve_prev_index = boost::none; - if(_subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[pathv[_index].size() - 1]; - } else if(!pathv[_index].closed() || _subindex != 0) { - curve_prev_index = _subindex - 1; + if(subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[_index].size() - 1; + } else if(!pathv[_index].closed() || subindex != 0) { + curve_prev_index = subindex - 1; } if (curve_prev_index) { Geom::Curve const &curve_in = pathv[_index][*curve_prev_index]; - double s = satellite.arcDistance(pathv[_index][_subindex]); + double s = satellite.arcDistance(pathv[_index][subindex]); double t = satellite.time(s, true, curve_in); if (t > 1) { t = 1; @@ -375,7 +380,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const tmp_point = (curve_in).pointAt(t); } } else { - tmp_point = satellite.getPosition(pathv[_index][_subindex]); + tmp_point = satellite.getPosition(pathv[_index][subindex]); } Geom::Point const canvas_point = tmp_point; return canvas_point; @@ -386,19 +391,18 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) if (!_pparam->_last_pointwise) { return; } - size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { - _pparam->_vector[_index][_subindex].amount = 0.0; + _pparam->_vector[_index][subindex].amount = 0.0; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); } else { using namespace Geom; - SatelliteType type = _pparam->_vector[_index][_subindex].satellite_type; + SatelliteType type = _pparam->_vector[_index][subindex].satellite_type; switch (type) { case FILLET: type = INVERSE_FILLET; @@ -438,13 +442,13 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - Geom::PathVector pathv = pparam->_last_pointwise->getPV(); - double amount = _pparam->_vector[_index][_subindex].amount; + Geom::PathVector pathv = _pparam->_last_pointwise->getPV(); + double amount = _pparam->_vector[_index][subindex].amount; boost::optional curve_prev_index = boost::none; - if(_subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[pathv[_index].size() - 1]; - } else if(!pathv[_index].closed() || _subindex != 0) { - curve_prev_index = _subindex - 1; + if(subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[_index].size() - 1; + } else if(!pathv[_index].closed() || subindex != 0) { + curve_prev_index = subindex - 1; } if (!_pparam->_use_distance && !_pparam->_vector[_index][subindex].is_time) { if (curve_prev_index) { @@ -454,10 +458,9 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } bool aprox = false; - Geom::D2 d2_out = _pparam->_last_pointwise->getPwd2()[_index][subindex]; + Geom::D2 d2_out = pathv[_index][subindex].toSBasis(); if (curve_prev_index) { - Geom::D2 d2_in = - _pparam->_last_pointwise->getPwd2()[_index][*curve_prev_index]; + Geom::D2 d2_in = pathv[_index][*curve_prev_index].toSBasis(); aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->_use_distance @@ -483,17 +486,16 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double amount = satellite.amount; double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { - Geom::Piecewise > pwd2 = _pparam->_last_pointwise->getPwd2(); - Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01); - Geom::Path sat_path = pathv.pathAt(index); + Pointwise *pointwise = _pparam->_last_pointwise; + Geom::PathVector pathv = pointwise->getPV(); boost::optional curve_prev_index = boost::none; - if(_subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[pathv[_index].size() - 1]; - } else if(!pathv[_index].closed() || _subindex != 0) { - curve_prev_index = _subindex - 1; + if(subindex == 0 && pathv[_index].closed()){ + curve_prev_index = pathv[_index].size() - 1; + } else if(!pathv[_index].closed() || subindex != 0) { + curve_prev_index = subindex - 1; } if (curve_prev_index) { - amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][*prev], pathv[_index][subindex]); + amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][*curve_prev_index], pathv[_index][subindex]); } else { amount = 0.0; } diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index db3776ba3..9a9ec4a88 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -30,7 +30,7 @@ namespace LivePathEffect { class FilletChamferKnotHolderEntity; -class SatellitesArrayParam : public ArrayArrayParam { +class SatellitesArrayParam : public ArrayParam > { public: SatellitesArrayParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.h b/src/ui/dialog/lpe-fillet-chamfer-properties.h index f982db286..105cafe68 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; -- cgit v1.2.3 From b03cc6d03c9cfa57ebee8c70412e96c5d92f4f83 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 11 May 2016 22:27:45 +0200 Subject: pre-remove of subpath update satellites (bzr r13645.1.132) --- src/helper/geom-pointwise.cpp | 147 +++++++++++++------------ src/live_effects/lpe-fillet-chamfer.cpp | 28 +++-- src/live_effects/parameter/satellitesarray.cpp | 1 + 3 files changed, 90 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index a7082ec24..1fbed612c 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 ab1cf41e3..7379efcf6 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -410,22 +410,21 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } } //if are diferent sizes call to poinwise recalculate - //todo: fire a reverse satellites on reverse path. Maybe a new method - //like "are_similar" to avoid precission issues on reverse a pointwise - //and after convert to Pathvector + //TODO: Update the satellite data in paths modified, Goal 0.93 if (pointwise && number_nodes != pointwise->getTotalSatellites()) { - std::cout << "gasdfgffffffffffffffffffffffffffffffffffffffffffffffffff\n"; + pointwise->setSatellites(satellites); Satellite satellite(satellites[0][0].satellite_type); satellite.setIsTime(satellites[0][0].is_time); satellite.setHasMirror(satellites[0][0].has_mirror); pointwise->recalculateForNewPwd2(pwd2, pathv, satellite); + satellites_param.setPointwise(pointwise); } else { pointwise = new Pointwise(); pointwise->setPwd2(pwd2); pointwise->setSatellites(satellites); + satellites_param.setPointwise(pointwise); + refreshKnots(); } - satellites_param.setPointwise(pointwise); - refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -477,16 +476,15 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } continue; } + if (curve_next_index && *curve_next_index != pathv[path].size() - 1 && pathv[path][*curve_next_index].isDegenerate()) { + curve_next_index = *curve_next_index + 1; + } Geom::Curve const &curve_it2 = pathv[path][*curve_next_index]; -// if (curve != pathv[path].size() && (*curve_it2).isDegenerate()) { -// ++curve_it2; -// } -// if ((*curve_it1).isDegenerate()) { -// ++curve_it1; -// counter_curves++; -// time0 = 0.0; -// continue; -// } + if ((*curve_it1).isDegenerate()) { + curve++; + time0 = 0.0; + continue; + } Satellite satellite = satellites[path][*curve_next_index]; if (!curve) { //curve == 0 if (!path_it->closed()) { diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 9f14a1d5b..8e6ba0b41 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -339,6 +339,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const return Geom::Point(Geom::infinity(), Geom::infinity()); } Geom::PathVector pathv = pointwise->getPV(); + if (pathv[_index].size() <= subindex){ //We know this path is open and is last satellite. Hide it _pparam->_vector[_index][subindex].hidden = true; return Geom::Point(Geom::infinity(), Geom::infinity()); -- cgit v1.2.3 From c103f187da67d1e2a9d31f45248a415945b1e5c7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 13 May 2016 22:09:34 +0200 Subject: Fiximg pointwise (bzr r13645.1.133) --- src/helper/geom-pointwise.cpp | 32 ++++++++++++++++++++++++-------- src/live_effects/lpe-fillet-chamfer.cpp | 14 ++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 1fbed612c..a4e5530a4 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 7379efcf6..6ecffb388 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -360,6 +360,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if(!_hp.empty()) { _hp.clear(); } + std::cout << "1\n"; SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { @@ -368,6 +369,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if (path) { c = path->get_original_curve(); } + std::cout << "2\n"; //fillet chamfer specific calls satellites_param.setUseDistance(use_knot_distance); //mandatory call @@ -409,9 +411,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].hidden = hide_knots; } } + std::cout << "3\n"; //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 if (pointwise && number_nodes != pointwise->getTotalSatellites()) { + std::cout << "4\n"; pointwise->setSatellites(satellites); Satellite satellite(satellites[0][0].satellite_type); satellite.setIsTime(satellites[0][0].is_time); @@ -419,12 +423,14 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise->recalculateForNewPwd2(pwd2, pathv, satellite); satellites_param.setPointwise(pointwise); } else { + std::cout << "5\n"; pointwise = new Pointwise(); pointwise->setPwd2(pwd2); pointwise->setSatellites(satellites); satellites_param.setPointwise(pointwise); refreshKnots(); } + std::cout << "6\n"; } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -443,8 +449,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::PathVector path_out; size_t path = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); + std::cout << "7\n"; Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { + std::cout << "8\n"; if (path_it->empty()) { continue; } @@ -467,6 +475,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } else if (curve != pathv[path].size() -1 || !pathv[path].closed()) { curve_next_index = curve + 1; } + std::cout << *curve_next_index << "\n"; if (curve == pathv[path].size() -1 && !pathv[path].closed()) { //the path is open and we are at end of path if (time0 != 1) { //Previous satellite not at 100% amount Geom::Curve *last_curve = curve_it1->portion(time0, 1); @@ -479,6 +488,11 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (curve_next_index && *curve_next_index != pathv[path].size() - 1 && pathv[path][*curve_next_index].isDegenerate()) { curve_next_index = *curve_next_index + 1; } + std::cout << *curve_next_index << "\n"; + std::cout << pathv[path].size() << "pathv[path].size()\n"; + std::cout << path << "\n"; + std::cout << satellites.size() << "\n"; + std::cout << satellites[path].size() << "\n"; Geom::Curve const &curve_it2 = pathv[path][*curve_next_index]; if ((*curve_it1).isDegenerate()) { curve++; -- cgit v1.2.3 From 4c145e43f8ab8d8040fb2fa42309f7bd400f6349 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 14 May 2016 23:52:45 +0200 Subject: Fixing pointwise (bzr r13645.1.135) --- src/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 +- src/live_effects/parameter/satellitesarray.cpp | 231 ++++++++++++------------- src/live_effects/parameter/satellitesarray.h | 8 +- 8 files changed, 191 insertions(+), 382 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index a4e5530a4..6ed6e8f83 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 fa03a5db7..047de8dd3 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 6ecffb388..f8f17fccf 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -54,8 +54,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) apply_no_radius(_("Apply changes if radius = 0"), _("Apply changes if radius = 0"), "apply_no_radius", &wr, this, true), apply_with_radius(_("Apply changes if radius > 0"), _("Apply changes if radius > 0"), "apply_with_radius", &wr, this, true), helper_size(_("Helper size with direction:"), - _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise(NULL) + _("Helper size with direction"), "helper_size", &wr, this, 0) { registerParameter(&satellites_param); registerParameter(&method); @@ -82,7 +81,6 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) helper_size.param_set_increments(5, 5); helper_size.param_set_digits(0); //helper_size.param_overwrite_widget(true); - } void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) @@ -117,12 +115,8 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } satellites.push_back(subpath_satellites); } - pointwise = new Pointwise(); - //Why Pwd2? Could we switch all to pathvector instead? - //I usualy use a pathvector, except some curve operations with D2 - //if yes maybe "poinwise" need a rename - pointwise->setPwd2(paths_to_pw(pathv)); - pointwise->setSatellites(satellites); + pointwise.setPathVector(pathv); + pointwise.setSatellites(satellites); satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); @@ -258,15 +252,15 @@ void LPEFilletChamfer::updateAmount() } else { power = radius / 100; } - Satellites satellites = pointwise->getSatellites(); - Geom::PathVector pathv = pointwise->getPV(); + Satellites satellites = pointwise.getSatellites(); + Geom::PathVector pathv = pointwise.getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { - boost::optional curve_prev_index = boost::none; + boost::optional previous_index = boost::none; if(j == 0 && pathv[i].closed()){ - curve_prev_index = pathv[i].size() - 1; + previous_index = pathv[i].size() - 1; } else if(!pathv[i].closed() || j != 0) { - curve_prev_index = j - 1; + previous_index = j - 1; } if (!pathv[i].closed() && j == 0) { satellites[i][j].amount = 0; @@ -284,8 +278,8 @@ void LPEFilletChamfer::updateAmount() Geom::Point satellite_point = pathv[i].pointAt(j); if (isNodePointSelected(satellite_point) || !only_selected) { if (!use_knot_distance && !flexible) { - if(curve_prev_index) { - satellites[i][j].amount = satellites[i][j].radToLen(power, pathv[i][*curve_prev_index], pathv[i][j]); + if(previous_index) { + satellites[i][j].amount = satellites[i][j].radToLen(power, pathv[i][*previous_index], pathv[i][j]); } else { satellites[i][j].amount = 0.0; } @@ -295,14 +289,14 @@ void LPEFilletChamfer::updateAmount() } } } - pointwise->setSatellites(satellites); + pointwise.setSatellites(satellites); satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() { - Satellites satellites = pointwise->getSatellites(); - Geom::PathVector pathv = pointwise->getPV(); + Satellites satellites = pointwise.getSatellites(); + Geom::PathVector pathv = pointwise.getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if ((!apply_no_radius && satellites[i][j].amount == 0) || @@ -320,14 +314,14 @@ void LPEFilletChamfer::updateChamferSteps() } } } - pointwise->setSatellites(satellites); + pointwise.setSatellites(satellites); satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - Satellites satellites = pointwise->getSatellites(); - Geom::PathVector pathv = pointwise->getPV(); + Satellites satellites = pointwise.getSatellites(); + Geom::PathVector pathv = pointwise.getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if ((!apply_no_radius && satellites[i][j].amount == 0) || @@ -351,16 +345,12 @@ void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) } } } - pointwise->setSatellites(satellites); + pointwise.setSatellites(satellites); satellites_param.setPointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { - if(!_hp.empty()) { - _hp.clear(); - } - std::cout << "1\n"; SPLPEItem *splpeitem = const_cast(lpeItem); SPShape *shape = dynamic_cast(splpeitem); if (shape) { @@ -369,14 +359,12 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if (path) { c = path->get_original_curve(); } - std::cout << "2\n"; //fillet chamfer specific calls satellites_param.setUseDistance(use_knot_distance); //mandatory call satellites_param.setEffectType(effectType()); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - Geom::Piecewise > pwd2 = remove_short_cuts(paths_to_pw(pathv), 0.01);; Satellites satellites = satellites_param.data(); if(satellites.empty()) { doOnApply(lpeItem); @@ -411,26 +399,23 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].hidden = hide_knots; } } - std::cout << "3\n"; //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 - if (pointwise && number_nodes != pointwise->getTotalSatellites()) { - std::cout << "4\n"; - pointwise->setSatellites(satellites); + size_t satellites_counter = pointwise.getTotalSatellites(); + if (satellites_counter != 0 && number_nodes != satellites_counter) { + pointwise.setSatellites(satellites); Satellite satellite(satellites[0][0].satellite_type); satellite.setIsTime(satellites[0][0].is_time); - satellite.setHasMirror(satellites[0][0].has_mirror); - pointwise->recalculateForNewPwd2(pwd2, pathv, satellite); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hide_knots); + pointwise.recalculateForNewPathVector(pathv, satellite); satellites_param.setPointwise(pointwise); } else { - std::cout << "5\n"; - pointwise = new Pointwise(); - pointwise->setPwd2(pwd2); - pointwise->setSatellites(satellites); + pointwise.setPathVector(pathv); + pointwise.setSatellites(satellites); satellites_param.setPointwise(pointwise); refreshKnots(); } - std::cout << "6\n"; } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -449,10 +434,8 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::PathVector path_out; size_t path = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - std::cout << "7\n"; Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { - std::cout << "8\n"; if (path_it->empty()) { continue; } @@ -467,39 +450,21 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } double time0 = 0; size_t curve = 0; - Satellites satellites = pointwise->getSatellites(); + Satellites satellites = pointwise.getSatellites(); for (Geom::Path::const_iterator curve_it1 = path_it->begin(); curve_it1 != path_it->end(); ++curve_it1) { - boost::optional curve_next_index = boost::none; + size_t next_index = curve + 1; if (curve == pathv[path].size() - 1 && pathv[path].closed()) { - curve_next_index = 0; - } else if (curve != pathv[path].size() -1 || !pathv[path].closed()) { - curve_next_index = curve + 1; + next_index = 0; } - std::cout << *curve_next_index << "\n"; if (curve == pathv[path].size() -1 && !pathv[path].closed()) { //the path is open and we are at end of path if (time0 != 1) { //Previous satellite not at 100% amount Geom::Curve *last_curve = curve_it1->portion(time0, 1); last_curve->setInitial(tmp_path.finalPoint()); tmp_path.append(*last_curve); - delete last_curve; } continue; } - if (curve_next_index && *curve_next_index != pathv[path].size() - 1 && pathv[path][*curve_next_index].isDegenerate()) { - curve_next_index = *curve_next_index + 1; - } - std::cout << *curve_next_index << "\n"; - std::cout << pathv[path].size() << "pathv[path].size()\n"; - std::cout << path << "\n"; - std::cout << satellites.size() << "\n"; - std::cout << satellites[path].size() << "\n"; - Geom::Curve const &curve_it2 = pathv[path][*curve_next_index]; - if ((*curve_it1).isDegenerate()) { - curve++; - time0 = 0.0; - continue; - } - Satellite satellite = satellites[path][*curve_next_index]; + Satellite satellite = satellites[path][next_index]; if (!curve) { //curve == 0 if (!path_it->closed()) { time0 = 0; @@ -508,10 +473,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } } bool last = pathv[path].size() - 1 == curve; + Geom::Curve const &curve_it2 = pathv[path][next_index]; double s = satellite.arcDistance(curve_it2); double time1 = satellite.time(s, true, (*curve_it1)); double time2 = satellite.time(curve_it2); - if (time1 <= time0) { time1 = time0; } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index a209971dd..7603c7de4 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -60,7 +60,7 @@ private: BoolParam apply_with_radius; ScalarParam helper_size; - Pointwise *pointwise; + Pointwise pointwise; Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index c9e2d6563..3d2e7773d 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -13,44 +13,6 @@ namespace Inkscape { namespace LivePathEffect { -//TODO: move maybe -unsigned int -sp_svg_satellite_vector_read_d(gchar const *str, std::vector *subpath_satellites){ - if (!str) { - return 0; - } - gchar ** strarray = g_strsplit(str, " @ ", 0); - gchar ** iter = strarray; - while (*iter != NULL) { - gchar ** strsubarray = g_strsplit(*iter, ",", 7); - if(strlen(str) > 0 && strsubarray[6] && !strsubarray[7]){ - Satellite satellite; - satellite.setSatelliteType(g_strstrip(strsubarray[0])); - satellite.is_time = strncmp(strsubarray[1],"1",1) == 0; - satellite.has_mirror = strncmp(strsubarray[2],"1",1) == 0; - satellite.hidden = strncmp(strsubarray[3],"1",1) == 0; - double amount,angle; - float stepsTmp; - sp_svg_number_read_d(strsubarray[4], &amount); - sp_svg_number_read_d(strsubarray[5], &angle); - sp_svg_number_read_f(strsubarray[6], &stepsTmp); - unsigned int steps = (unsigned int)stepsTmp; - satellite.amount = amount; - satellite.angle = angle; - satellite.steps = steps; - subpath_satellites->push_back(satellite); - g_strfreev (strsubarray); - } - iter++; - } - g_strfreev (strarray); - if (!subpath_satellites->empty()){ - return 1; - } - return 0; -} - - template <> double ArrayParam::readsvg(const gchar * str) @@ -89,11 +51,35 @@ template <> std::vector ArrayParam >::readsvg(const gchar * str) { - std::vector subpath_satellites; - if (sp_svg_satellite_vector_read_d(str, &subpath_satellites)) { + std::vector subpath_satellites; + if (!str) { return subpath_satellites; } - subpath_satellites.push_back(Satellite(FILLET)); + gchar ** strarray = g_strsplit(str, "@", 0); + gchar ** iter = strarray; + while (*iter != NULL) { + gchar ** strsubarray = g_strsplit(*iter, ",", 7); + if(*strsubarray[6]){ + Satellite satellite; + satellite.setSatelliteType(g_strstrip(strsubarray[0])); + satellite.is_time = strncmp(strsubarray[1],"1",1) == 0; + satellite.has_mirror = strncmp(strsubarray[2],"1",1) == 0; + satellite.hidden = strncmp(strsubarray[3],"1",1) == 0; + double amount,angle; + float stepsTmp; + sp_svg_number_read_d(strsubarray[4], &amount); + sp_svg_number_read_d(strsubarray[5], &angle); + sp_svg_number_read_f(g_strstrip(strsubarray[6]), &stepsTmp); + unsigned int steps = (unsigned int)stepsTmp; + satellite.amount = amount; + satellite.angle = angle; + satellite.steps = steps; + subpath_satellites.push_back(satellite); + } + g_strfreev (strsubarray); + iter++; + } + g_strfreev (strarray); return subpath_satellites; } diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 64d01650c..8a9d72fe3 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -51,7 +51,7 @@ public: virtual bool param_readSVGValue(const gchar * strvalue) { _vector.clear(); - gchar ** strarray = g_strsplit(strvalue, " | ", 0); + gchar ** strarray = g_strsplit(strvalue, "|", 0); gchar ** iter = strarray; while (*iter != NULL) { _vector.push_back( readsvg(*iter) ); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 8e6ba0b41..be4eb6732 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -12,7 +12,6 @@ #include "live_effects/effect.h" #include "sp-lpe-item.h" #include -#include // TODO due to internal breakage in glibmm headers, // this has to be included last. #include @@ -34,7 +33,6 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, _helper_size = 0; _use_distance = false; _effectType = FILLET_CHAMFER; - _last_pointwise = NULL; } void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, @@ -46,10 +44,10 @@ void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, _knot_color = color; } -void SatellitesArrayParam::setPointwise(Pointwise *pointwise) +void SatellitesArrayParam::setPointwise(Pointwise pointwise) { _last_pointwise = pointwise; - param_set_and_write_new_value(_last_pointwise->getSatellites()); + param_set_and_write_new_value(_last_pointwise.getSatellites()); } void SatellitesArrayParam::setUseDistance(bool use_knot_distance) @@ -67,51 +65,51 @@ void SatellitesArrayParam::setHelperSize(int hs) _helper_size = hs; updateCanvasIndicators(); } - +bool SatellitesArrayParam::validData() +{ + return _last_pointwise.getPathVector().nodes().size() == _last_pointwise.getTotalSatellites(); +} void SatellitesArrayParam::updateCanvasIndicators(bool mirror) { - if (!_last_pointwise) { + if (!validData()) { + return; + } + if(!_hp.empty()) { + _hp.clear(); + } + Geom::PathVector pathv = _last_pointwise.getPathVector(); + if (pathv.empty()) { return; } - Geom::PathVector pathv = _last_pointwise->getPV(); if (mirror == true) { _hp.clear(); } if (_effectType == FILLET_CHAMFER) { for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { - if ( _vector[i][j].hidden) { - continue; - } - if ((!_vector[i][j].has_mirror && mirror == true) || _vector[i][j].amount == 0) { - continue; - } - double pos = 0; - if (pathv[i].size() == j) { //ignore last satellite in open paths with fillet chamfer effect + if (_vector[i][j].hidden || //Ignore if hidden + (!_vector[i][j].has_mirror && mirror == true) || //Ignore if not have mirror and we are in mirror loop + _vector[i][j].amount == 0 || //no helper in 0 value + pathv[i].size() == j || //ignore last satellite in open paths with fillet chamfer effect + !pathv[i].closed() && j == 0) //ignore first satellites on open paths + { continue; } Geom::Curve *curve_in = pathv[i][j].duplicate(); + double pos = 0; bool overflow = false; double size_out = _vector[i][j].arcDistance(*curve_in); double lenght_out = curve_in->length(); - double lenght_in = 0; - - boost::optional curve_prev_index = boost::none; + size_t previous_index = j - 1; //Always are previous index because we skip first satellite on open paths if(j == 0 && pathv[i].closed()){ - curve_prev_index = pathv[i].size() - 1; - } else if(!pathv[i].closed() || j != 0) { - curve_prev_index = j - 1; - } - if (curve_prev_index) { - lenght_in = pathv.curveAt(*curve_prev_index).length(); + previous_index = pathv[i].size() - 1; } + double lenght_in = pathv.curveAt(previous_index).length(); if (mirror) { - if (curve_prev_index) { - curve_in = const_cast(&pathv.curveAt(*curve_prev_index)); - pos = _vector[i][j].time(size_out, true, *curve_in); - if (lenght_out < size_out) { - overflow = true; - } + curve_in = const_cast(&pathv.curveAt(previous_index)); + pos = _vector[i][j].time(size_out, true, *curve_in); + if (lenght_out < size_out) { + overflow = true; } } else { pos = _vector[i][j].time(*curve_in); @@ -191,8 +189,7 @@ void SatellitesArrayParam::addCanvasIndicators( hp_vec.push_back(_hp); } -void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, - bool /*set*/) +void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, bool /*set*/) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -212,6 +209,10 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror) { + if (!validData()) { + return; + } + Geom::PathVector pathv = _last_pointwise.getPathVector(); for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { if (!_vector[i][j].has_mirror && mirror) { @@ -226,6 +227,9 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, using namespace Geom; //If is for filletChamfer effect... if (_effectType == FILLET_CHAMFER) { + if(!pathv[i].closed() && (j == 0 || j == _vector[i].size() -1)) { + continue; + } const gchar *tip; if (type == CHAMFER) { tip = _("Chamfer: Ctrl+Click toggle type, " @@ -271,48 +275,41 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) { + if (! _pparam->validData() || !valid_index(_index)) { + return; + } Geom::Point s = snap_knot_position(p, state); size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } - if (!valid_index(_index)) { - return; - } - - if (!_pparam->_last_pointwise) { - return; - } - Satellite satellite = _pparam->_vector[_index][subindex]; - if (satellite.hidden) { + Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + if (satellite.hidden || + !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths + pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + { return; } - Pointwise *pointwise = _pparam->_last_pointwise; - Geom::PathVector pathv = pointwise->getPV(); if (subindex != _subindex) { - boost::optional curve_prev_index = boost::none; + size_t previous_index = subindex - 1; if(subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[_index].size() - 1; - } else if(!pathv[_index].closed() || subindex != 0) { - curve_prev_index = subindex - 1; + previous_index = pathv[_index].size() - 1; } - if (curve_prev_index) { - Geom::Curve const &curve_in = pathv[_index][*curve_prev_index]; - double mirror_time = Geom::nearest_time(s, curve_in); - double time_start = 0; - Satellites satellites = pointwise->getSatellites(); - time_start = satellites[_index][*curve_prev_index].time(curve_in); - if (time_start > mirror_time) { - mirror_time = time_start; - } - double size = arcLengthAt(mirror_time, curve_in); - double amount = curve_in.length() - size; - if (satellite.is_time) { - amount = timeAtArcLength(amount, pathv[_index][subindex]); - } - satellite.amount = amount; + Geom::Curve const &curve_in = pathv[_index][previous_index]; + double mirror_time = Geom::nearest_time(s, curve_in); + double time_start = 0; + Satellites satellites = _pparam->_last_pointwise.getSatellites(); + time_start = satellites[_index][previous_index].time(curve_in); + if (time_start > mirror_time) { + mirror_time = time_start; } + double size = arcLengthAt(mirror_time, curve_in); + double amount = curve_in.length() - size; + if (satellite.is_time) { + amount = timeAtArcLength(amount, pathv[_index][subindex]); + } + satellite.amount = amount; } else { satellite.setPosition(s, pathv[_index][subindex]); } @@ -325,61 +322,45 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point FilletChamferKnotHolderEntity::knot_get() const { + if (! _pparam->validData() || !valid_index(_index)) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } Geom::Point tmp_point; size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } - if (!valid_index(_index)) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } Satellite satellite = _pparam->_vector[_index][subindex]; - Pointwise *pointwise = _pparam->_last_pointwise; - if (!pointwise) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - Geom::PathVector pathv = pointwise->getPV(); - - if (pathv[_index].size() <= subindex){ //We know this path is open and is last satellite. Hide it + Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + if (satellite.hidden || + !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths + pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + { _pparam->_vector[_index][subindex].hidden = true; return Geom::Point(Geom::infinity(), Geom::infinity()); } - if (!pathv[_index].closed() && subindex == 0){ //Path is open hide first satellite - _pparam->_vector[_index][subindex].hidden = true; - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - if (satellite.hidden) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } - if (subindex != _subindex && !_pparam->_vector[_index][subindex].has_mirror) { - return Geom::Point(Geom::infinity(), Geom::infinity()); - } this->knot->show(); if (subindex != _subindex) { tmp_point = satellite.getPosition(pathv[_index][subindex]); - boost::optional curve_prev_index = boost::none; + size_t previous_index = subindex - 1; if(subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[_index].size() - 1; - } else if(!pathv[_index].closed() || subindex != 0) { - curve_prev_index = subindex - 1; + previous_index = pathv[_index].size() - 1; } - if (curve_prev_index) { - Geom::Curve const &curve_in = pathv[_index][*curve_prev_index]; - double s = satellite.arcDistance(pathv[_index][subindex]); - double t = satellite.time(s, true, curve_in); - if (t > 1) { - t = 1; - } - if (t < 0) { - t = 0; - } - double time_start = 0; - time_start = pointwise->getSatellites()[_index][*curve_prev_index].time(curve_in); - if (time_start > t) { - t = time_start; - } - tmp_point = (curve_in).pointAt(t); + Geom::Curve const &curve_in = pathv[_index][previous_index]; + double s = satellite.arcDistance(pathv[_index][subindex]); + double t = satellite.time(s, true, curve_in); + if (t > 1) { + t = 1; + } + if (t < 0) { + t = 0; } + double time_start = 0; + time_start = _pparam->_last_pointwise.getSatellites()[_index][previous_index].time(curve_in); + if (time_start > t) { + t = time_start; + } + tmp_point = (curve_in).pointAt(t); } else { tmp_point = satellite.getPosition(pathv[_index][subindex]); } @@ -389,13 +370,19 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const void FilletChamferKnotHolderEntity::knot_click(guint state) { - if (!_pparam->_last_pointwise) { + if (! _pparam->validData() || !valid_index(_index)) { return; } size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } + Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + if (!pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths + pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + { + return; + } if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { _pparam->_vector[_index][subindex].amount = 0.0; @@ -443,25 +430,22 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - Geom::PathVector pathv = _pparam->_last_pointwise->getPV(); double amount = _pparam->_vector[_index][subindex].amount; - boost::optional curve_prev_index = boost::none; + size_t previous_index = subindex - 1; if(subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[_index].size() - 1; - } else if(!pathv[_index].closed() || subindex != 0) { - curve_prev_index = subindex - 1; + previous_index = pathv[_index].size() - 1; } if (!_pparam->_use_distance && !_pparam->_vector[_index][subindex].is_time) { - if (curve_prev_index) { - amount = _pparam->_vector[_index][subindex].lenToRad(amount, pathv[_index][*curve_prev_index], pathv[_index][subindex], _pparam->_vector[_index][*curve_prev_index]); + if (previous_index) { + amount = _pparam->_vector[_index][subindex].lenToRad(amount, pathv[_index][previous_index], pathv[_index][subindex], _pparam->_vector[_index][previous_index]); } else { amount = 0.0; } } bool aprox = false; Geom::D2 d2_out = pathv[_index][subindex].toSBasis(); - if (curve_prev_index) { - Geom::D2 d2_in = pathv[_index][*curve_prev_index].toSBasis(); + if (previous_index) { + Geom::D2 d2_in = pathv[_index][previous_index].toSBasis(); aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->_use_distance @@ -477,29 +461,28 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) { - if (!_pparam->_last_pointwise) { + if (! _pparam->validData() || !valid_index(_index)) { return; } size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } + Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + if (satellite.hidden || + !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths + pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + { + return; + } double amount = satellite.amount; double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { - Pointwise *pointwise = _pparam->_last_pointwise; - Geom::PathVector pathv = pointwise->getPV(); - boost::optional curve_prev_index = boost::none; + size_t previous_index = subindex - 1; if(subindex == 0 && pathv[_index].closed()){ - curve_prev_index = pathv[_index].size() - 1; - } else if(!pathv[_index].closed() || subindex != 0) { - curve_prev_index = subindex - 1; - } - if (curve_prev_index) { - amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][*curve_prev_index], pathv[_index][subindex]); - } else { - amount = 0.0; + previous_index = pathv[_index].size() - 1; } + amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][previous_index], pathv[_index][subindex]); if (max_amount > 0 && amount == 0) { amount = _pparam->_vector[_index][subindex].amount; } diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index 9a9ec4a88..dcd82ada5 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -56,9 +56,9 @@ public: void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); void setEffectType(EffectType et); - void setPointwise(Pointwise *pointwise); - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); + void setPointwise(Pointwise pointwise); + bool validData(); + void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); friend class FilletChamferKnotHolderEntity; friend class LPEFilletChamfer; @@ -77,7 +77,7 @@ private: int _helper_size; bool _use_distance; EffectType _effectType; - Pointwise *_last_pointwise; + Pointwise _last_pointwise; }; -- cgit v1.2.3 From 159439c26042b7c69aa9c33ce9484e4dfd00372a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 15 May 2016 11:48:51 +0200 Subject: Fixing pointwise (bzr r13645.1.137) --- src/live_effects/lpe-fillet-chamfer.cpp | 6 ++++- src/live_effects/parameter/array.h | 32 +++++++++++++------------- src/live_effects/parameter/satellitesarray.cpp | 10 ++++++++ src/live_effects/parameter/satellitesarray.h | 5 ++-- src/ui/tool/multi-path-manipulator.cpp | 10 ++++---- 5 files changed, 39 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f8f17fccf..9c633ea57 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -363,6 +363,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites_param.setUseDistance(use_knot_distance); //mandatory call satellites_param.setEffectType(effectType()); + satellites_param.setPathUpdate(false); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); Satellites satellites = satellites_param.data(); @@ -402,8 +403,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 size_t satellites_counter = pointwise.getTotalSatellites(); + if (satellites_counter != 0 ){ + std::cout << number_nodes << "aaaaa" << pointwise.getTotalSatellites() << "\n"; + } if (satellites_counter != 0 && number_nodes != satellites_counter) { - pointwise.setSatellites(satellites); + satellites_param.setPathUpdate(true); Satellite satellite(satellites[0][0].satellite_type); satellite.setIsTime(satellites[0][0].is_time); satellite.setHasMirror(mirror_knots); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 8a9d72fe3..9802abc2e 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -89,7 +89,7 @@ protected: size_t _default_size; void writesvg(SVGOStringStream &str, std::vector const &vector) const { - for (size_t i = 0; i < vector.size(); ++i) { + for (unsigned int i = 0; i < vector.size(); ++i) { if (i != 0) { // separate items with pipe symbol str << " | "; @@ -98,37 +98,37 @@ protected: } } - void writesvgData(SVGOStringStream &str, float const &nVector) const { - str << nVector; + void writesvgData(SVGOStringStream &str, float const &vector_data) const { + str << vector_data; } - void writesvgData(SVGOStringStream &str, double const &nVector) const { - str << nVector; + void writesvgData(SVGOStringStream &str, double const &vector_data) const { + str << vector_data; } - void writesvgData(SVGOStringStream &str, Geom::Point const &nVector) const { - str << nVector; + void writesvgData(SVGOStringStream &str, Geom::Point const &vector_data) const { + str << vector_data; } - void writesvgData(SVGOStringStream &str, std::vector const &nVector) const { - for (size_t i = 0; i < nVector.size(); ++i) { + void writesvgData(SVGOStringStream &str, std::vector const &vector_data) const { + for (size_t i = 0; i < vector_data.size(); ++i) { if (i != 0) { // separate items with @ symbol ¿Any other? str << " @ "; } - str << nVector[i].getSatelliteTypeGchar(); + str << vector_data[i].getSatelliteTypeGchar(); str << ","; - str << nVector[i].is_time; + str << vector_data[i].is_time; str << ","; - str << nVector[i].has_mirror; + str << vector_data[i].has_mirror; str << ","; - str << nVector[i].hidden; + str << vector_data[i].hidden; str << ","; - str << nVector[i].amount; + str << vector_data[i].amount; str << ","; - str << nVector[i].angle; + str << vector_data[i].angle; str << ","; - str << nVector[i].steps; + str << vector_data[i].steps; } } diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index be4eb6732..14660acc4 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -48,6 +48,7 @@ void SatellitesArrayParam::setPointwise(Pointwise pointwise) { _last_pointwise = pointwise; param_set_and_write_new_value(_last_pointwise.getSatellites()); + } void SatellitesArrayParam::setUseDistance(bool use_knot_distance) @@ -60,6 +61,11 @@ void SatellitesArrayParam::setEffectType(EffectType et) _effectType = et; } +void SatellitesArrayParam::setPathUpdate(bool path_update) +{ + _path_update = path_update; +} + void SatellitesArrayParam::setHelperSize(int hs) { _helper_size = hs; @@ -67,6 +73,7 @@ void SatellitesArrayParam::setHelperSize(int hs) } bool SatellitesArrayParam::validData() { + if (_path_update) { return false;} return _last_pointwise.getPathVector().nodes().size() == _last_pointwise.getTotalSatellites(); } void SatellitesArrayParam::updateCanvasIndicators(bool mirror) @@ -323,6 +330,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point FilletChamferKnotHolderEntity::knot_get() const { if (! _pparam->validData() || !valid_index(_index)) { + this->knot->hide(); return Geom::Point(Geom::infinity(), Geom::infinity()); } Geom::Point tmp_point; @@ -336,10 +344,12 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect { + this->knot->hide(); _pparam->_vector[_index][subindex].hidden = true; return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); + std::cout << subindex << pathv[_index].size() << "----" << _pparam->_vector[_index].size() << "fgdgsdgsdgsdsdsgd\n"; if (subindex != _subindex) { tmp_point = satellite.getPosition(pathv[_index][subindex]); size_t previous_index = subindex - 1; diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index dcd82ada5..0cebb9cb4 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -55,6 +55,7 @@ public: } void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); + void setPathUpdate(bool path_update); void setEffectType(EffectType et); void setPointwise(Pointwise pointwise); bool validData(); @@ -76,6 +77,7 @@ private: Geom::PathVector _hp; int _helper_size; bool _use_distance; + bool _path_update; EffectType _effectType; Pointwise _last_pointwise; @@ -99,8 +101,7 @@ public: bool valid_index(size_t index) const { return (_pparam->_vector.size() > index); - } - ; + }; private: SatellitesArrayParam *_pparam; diff --git a/src/ui/tool/multi-path-manipulator.cpp b/src/ui/tool/multi-path-manipulator.cpp index 857f954ce..9ec6f733f 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"); } } -- cgit v1.2.3 From c511141b70995ca7295df4ae244d7cc626f6ab73 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 21 May 2016 23:06:15 +0200 Subject: Update to refresh knots (bzr r13645.1.139) --- src/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(-) (limited to 'src') diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp index 6ed6e8f83..5531bb849 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 047de8dd3..599234473 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 9c633ea57..fc31aa447 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -239,8 +239,11 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - if (satellites_param.knoth) { - satellites_param.knoth->update_knots(); + //Find another way to update knots satellites_param.knoth->update_knots(); do the thing + //but not updat the knot index on node delete + if (tools_isactive(desktop, TOOLS_NODES)) { + tools_switch(desktop, TOOLS_SELECT); + tools_switch(desktop, TOOLS_NODES); } } @@ -413,13 +416,12 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellite.setHasMirror(mirror_knots); satellite.setHidden(hide_knots); pointwise.recalculateForNewPathVector(pathv, satellite); - satellites_param.setPointwise(pointwise); } else { pointwise.setPathVector(pathv); pointwise.setSatellites(satellites); - satellites_param.setPointwise(pointwise); - refreshKnots(); } + satellites_param.setPointwise(pointwise); + refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 3d2e7773d..4e3037904 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -60,21 +60,21 @@ ArrayParam >::readsvg(const gchar * str) while (*iter != NULL) { gchar ** strsubarray = g_strsplit(*iter, ",", 7); if(*strsubarray[6]){ - Satellite satellite; - satellite.setSatelliteType(g_strstrip(strsubarray[0])); - satellite.is_time = strncmp(strsubarray[1],"1",1) == 0; - satellite.has_mirror = strncmp(strsubarray[2],"1",1) == 0; - satellite.hidden = strncmp(strsubarray[3],"1",1) == 0; + Satellite *satellite = new Satellite(); + satellite->setSatelliteType(g_strstrip(strsubarray[0])); + satellite->is_time = strncmp(strsubarray[1],"1",1) == 0; + satellite->has_mirror = strncmp(strsubarray[2],"1",1) == 0; + satellite->hidden = strncmp(strsubarray[3],"1",1) == 0; double amount,angle; float stepsTmp; sp_svg_number_read_d(strsubarray[4], &amount); sp_svg_number_read_d(strsubarray[5], &angle); sp_svg_number_read_f(g_strstrip(strsubarray[6]), &stepsTmp); unsigned int steps = (unsigned int)stepsTmp; - satellite.amount = amount; - satellite.angle = angle; - satellite.steps = steps; - subpath_satellites.push_back(satellite); + satellite->amount = amount; + satellite->angle = angle; + satellite->steps = steps; + subpath_satellites.push_back(*satellite); } g_strfreev (strsubarray); iter++; -- cgit v1.2.3 From ff9ec25d3afc0453ead52d3da10b754637c8207f Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 23 May 2016 20:25:20 +0200 Subject: Fixing pointwise (bzr r13645.1.141) --- src/live_effects/lpe-fillet-chamfer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index fc31aa447..a291776b7 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,9 +16,9 @@ #include <2geom/elliptical-arc.h> #include "knotholder.h" #include +#include "ui/tools-switch.h" // TODO due to internal breakage in glibmm headers, this must be last: #include - namespace Inkscape { namespace LivePathEffect { @@ -241,6 +241,7 @@ void LPEFilletChamfer::refreshKnots() { //Find another way to update knots satellites_param.knoth->update_knots(); do the thing //but not updat the knot index on node delete + SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (tools_isactive(desktop, TOOLS_NODES)) { tools_switch(desktop, TOOLS_SELECT); tools_switch(desktop, TOOLS_NODES); @@ -420,8 +421,8 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise.setPathVector(pathv); pointwise.setSatellites(satellites); } - satellites_param.setPointwise(pointwise); refreshKnots(); + satellites_param.setPointwise(pointwise); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } -- cgit v1.2.3 From 8d35486a82d04a28dc9f297147ad4666b34cde4a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 26 May 2016 19:37:15 +0200 Subject: Fixing pointwise (bzr r13645.1.143) --- src/live_effects/lpe-fillet-chamfer.cpp | 39 +++++++++--------- src/live_effects/parameter/satellitesarray.cpp | 56 +++++++++++++------------- src/live_effects/parameter/satellitesarray.h | 4 +- src/ui/tool/path-manipulator.cpp | 1 - 4 files changed, 48 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index a291776b7..6ec711de7 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -367,9 +367,21 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites_param.setUseDistance(use_knot_distance); //mandatory call satellites_param.setEffectType(effectType()); - satellites_param.setPathUpdate(false); - Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); + //if are diferent sizes call to poinwise recalculate + //TODO: Update the satellite data in paths modified, Goal 0.93 + size_t number_nodes = pathv.nodes().size(); + size_t satellites_counter = pointwise.getTotalSatellites(); + if (satellites_counter != 0 && number_nodes != satellites_counter) { + Satellite satellite(FILLET); + satellite.setIsTime(flexible); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hide_knots); + pointwise.recalculateForNewPathVector(pathv, satellite); + satellites_param.setPointwise(pointwise); + refreshKnots(); + return; + } Satellites satellites = satellites_param.data(); if(satellites.empty()) { doOnApply(lpeItem); @@ -380,7 +392,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { satellites_param.setHelperSize(helper_size); } - size_t number_nodes = pathv.nodes().size(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if (satellites[i][j].is_time != flexible) { @@ -404,25 +415,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].hidden = hide_knots; } } - //if are diferent sizes call to poinwise recalculate - //TODO: Update the satellite data in paths modified, Goal 0.93 - size_t satellites_counter = pointwise.getTotalSatellites(); - if (satellites_counter != 0 ){ - std::cout << number_nodes << "aaaaa" << pointwise.getTotalSatellites() << "\n"; - } - if (satellites_counter != 0 && number_nodes != satellites_counter) { - satellites_param.setPathUpdate(true); - Satellite satellite(satellites[0][0].satellite_type); - satellite.setIsTime(satellites[0][0].is_time); - satellite.setHasMirror(mirror_knots); - satellite.setHidden(hide_knots); - pointwise.recalculateForNewPathVector(pathv, satellite); - } else { - pointwise.setPathVector(pathv); - pointwise.setSatellites(satellites); - } - refreshKnots(); + + pointwise.setPathVector(pathv); + pointwise.setSatellites(satellites); satellites_param.setPointwise(pointwise); + refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 14660acc4..78f1a945f 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -61,26 +61,25 @@ void SatellitesArrayParam::setEffectType(EffectType et) _effectType = et; } -void SatellitesArrayParam::setPathUpdate(bool path_update) -{ - _path_update = path_update; -} - void SatellitesArrayParam::setHelperSize(int hs) { _helper_size = hs; updateCanvasIndicators(); } -bool SatellitesArrayParam::validData() +bool SatellitesArrayParam::validData(size_t index,size_t subindex) { - if (_path_update) { return false;} - return _last_pointwise.getPathVector().nodes().size() == _last_pointwise.getTotalSatellites(); + if(!_last_pointwise.getPathVector().size() > index){ + return false; + } + if(!_last_pointwise.getPathVector()[index].size_closed() > subindex){ + return false; + } + return true; //_last_pointwise.getPathVector().nodes().size() == _last_pointwise.getTotalSatellites(); } + void SatellitesArrayParam::updateCanvasIndicators(bool mirror) { - if (!validData()) { - return; - } + if(!_hp.empty()) { _hp.clear(); } @@ -94,6 +93,9 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) if (_effectType == FILLET_CHAMFER) { for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { + if (!validData(i, j)) { + return; + } if (_vector[i][j].hidden || //Ignore if hidden (!_vector[i][j].has_mirror && mirror == true) || //Ignore if not have mirror and we are in mirror loop _vector[i][j].amount == 0 || //no helper in 0 value @@ -216,12 +218,12 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror) { - if (!validData()) { - return; - } Geom::PathVector pathv = _last_pointwise.getPathVector(); for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { + if (!validData(i, j)) { + return; + } if (!_vector[i][j].has_mirror && mirror) { continue; } @@ -282,14 +284,14 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) { - if (! _pparam->validData() || !valid_index(_index)) { - return; - } Geom::Point s = snap_knot_position(p, state); size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } + if (!_pparam->validData(_index, subindex)) { + return; + } Satellite satellite = _pparam->_vector[_index][subindex]; Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); if (satellite.hidden || @@ -329,15 +331,15 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point FilletChamferKnotHolderEntity::knot_get() const { - if (! _pparam->validData() || !valid_index(_index)) { - this->knot->hide(); - return Geom::Point(Geom::infinity(), Geom::infinity()); - } Geom::Point tmp_point; size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } + if (!_pparam->validData(_index, subindex)) { + this->knot->hide(); + return Geom::Point(Geom::infinity(), Geom::infinity()); + } Satellite satellite = _pparam->_vector[_index][subindex]; Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); if (satellite.hidden || @@ -380,13 +382,13 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const void FilletChamferKnotHolderEntity::knot_click(guint state) { - if (! _pparam->validData() || !valid_index(_index)) { - return; - } size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } + if (!_pparam->validData(_index, subindex)) { + return; + } Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); if (!pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect @@ -471,13 +473,13 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) { - if (! _pparam->validData() || !valid_index(_index)) { - return; - } size_t subindex = _subindex; if (_subindex >= _pparam->_vector[_index].size()) { subindex = _subindex - _pparam->_vector[_index].size(); } + if (!_pparam->validData(_index, subindex)) { + return; + } Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); if (satellite.hidden || !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index 0cebb9cb4..c6893f595 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -55,10 +55,9 @@ public: } void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); - void setPathUpdate(bool path_update); void setEffectType(EffectType et); void setPointwise(Pointwise pointwise); - bool validData(); + bool validData(size_t index, size_t subindex); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); friend class FilletChamferKnotHolderEntity; @@ -77,7 +76,6 @@ private: Geom::PathVector _hp; int _helper_size; bool _use_distance; - bool _path_update; EffectType _effectType; Pointwise _last_pointwise; diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp index 9d479432b..0d603ad1f 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 -- cgit v1.2.3 From 634be67d2fa8aa07d25d96e10a3ad24fdfdcc80e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 26 May 2016 20:44:19 +0200 Subject: Rename branch (bzr r13645.1.145) --- src/helper/CMakeLists.txt | 4 +- src/helper/Makefile_insert | 4 +- src/helper/geom-pathvectorsatellites.cpp | 74 ++++++++++++++++++++++++++ src/helper/geom-pathvectorsatellites.h | 53 ++++++++++++++++++ src/helper/geom-pointwise.cpp | 74 -------------------------- src/helper/geom-pointwise.h | 54 ------------------- src/live_effects/lpe-fillet-chamfer.cpp | 48 ++++++++--------- src/live_effects/lpe-fillet-chamfer.h | 4 +- src/live_effects/parameter/satellitesarray.cpp | 28 +++++----- src/live_effects/parameter/satellitesarray.h | 8 +-- 10 files changed, 175 insertions(+), 176 deletions(-) create mode 100644 src/helper/geom-pathvectorsatellites.cpp create mode 100644 src/helper/geom-pathvectorsatellites.h delete mode 100644 src/helper/geom-pointwise.cpp delete mode 100644 src/helper/geom-pointwise.h (limited to 'src') diff --git a/src/helper/CMakeLists.txt b/src/helper/CMakeLists.txt index aa99934b6..92709e4e9 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 54588d0ce..6ba0efbfa 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-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp new file mode 100644 index 000000000..a5207ab00 --- /dev/null +++ b/src/helper/geom-pathvectorsatellites.cpp @@ -0,0 +1,74 @@ +/** + * \file + * \brief PathVectorSatellites a class to manage a vector of satellites per piecewise node + */ /* + * Authors: + * Jabiertxof + * Nathan Hurst + * Johan Engelen + * Josh Andler + * suv + * Mc- + * Liam P. White + * Krzysztof Kosiński + * This code is in public domain + */ + +#include +Geom::PathVector PathVectorSatellites::getPathVector() const +{ + return _pathvector; +} + +void PathVectorSatellites::setPathVector(Geom::PathVector pathv) +{ + _pathvector = pathv; +} + +Satellites PathVectorSatellites::getSatellites() +{ + return _satellites; +} + +void PathVectorSatellites::setSatellites(Satellites satellites) +{ + _satellites = satellites; +} + +size_t PathVectorSatellites::getTotalSatellites() +{ + 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 PathVectorSatellites::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) +{ + Satellites 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); + } + setPathVector(pathv); + setSatellites(satellites); +} + +/* + 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-pathvectorsatellites.h b/src/helper/geom-pathvectorsatellites.h new file mode 100644 index 000000000..72ecef38f --- /dev/null +++ b/src/helper/geom-pathvectorsatellites.h @@ -0,0 +1,53 @@ +/** + * \file + * \brief PathVectorSatellites a class to manage a vector of satellites per piecewise node + */ /* + * Authors: + * Jabiertxof + * Nathan Hurst + * Johan Engelen + * Josh Andler + * suv + * Mc- + * Liam P. White + * Krzysztof Kosiński + * This code is in public domain + */ + +#ifndef SEEN_PATHVECTORSATELLITES_H +#define SEEN_PATHVECTORSATELLITES_H + +#include +#include <2geom/path.h> +#include <2geom/pathvector.h> + +/** + * @brief PathVectorSatellites a class to manage a vector of satellites per curve + */ +typedef std::vector > Satellites; +class PathVectorSatellites { +public: + Geom::PathVector getPathVector() const; + void setPathVector(Geom::PathVector pathv); + Satellites getSatellites(); + void setSatellites(Satellites satellites); + size_t getTotalSatellites(); + void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); +private: + Geom::PathVector _pathvector; + Satellites _satellites; +}; + +#endif //SEEN_PATHVECTORSATELLITES_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 deleted file mode 100644 index 5531bb849..000000000 --- a/src/helper/geom-pointwise.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/** - * \file - * \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 - * Krzysztof Kosiński - * This code is in public domain - */ - -#include -Geom::PathVector Pointwise::getPathVector() const -{ - return _pathvector; -} - -void Pointwise::setPathVector(Geom::PathVector pathv) -{ - _pathvector = pathv; -} - -Satellites Pointwise::getSatellites() -{ - return _satellites; -} - -void Pointwise::setSatellites(Satellites satellites) -{ - _satellites = 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) { - counter++; - } - } - return counter; -} - -void Pointwise::recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S) -{ - Satellites 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); - } - setPathVector(pathv); - setSatellites(satellites); -} - -/* - 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.h b/src/helper/geom-pointwise.h deleted file mode 100644 index 599234473..000000000 --- a/src/helper/geom-pointwise.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - * \file - * \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 - * Krzysztof Kosiński - * This code is in public domain - */ - -#ifndef SEEN_POINTWISE_H -#define SEEN_POINTWISE_H - -#include -#include <2geom/path.h> -#include <2geom/pathvector.h> -#include - -/** - * @brief Pointwise a class to manage a vector of satellites per curve - */ -typedef std::vector > Satellites; -class Pointwise { -public: - Geom::PathVector getPathVector() const; - void setPathVector(Geom::PathVector pathv); - Satellites getSatellites(); - size_t getTotalSatellites(); - void setSatellites(Satellites satellites); - void recalculateForNewPathVector(Geom::PathVector const pathv, Satellite const S); -private: - Geom::PathVector _pathvector; - Satellites _satellites; -}; - -#endif //SEEN_POINTWISE_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/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6ec711de7..56f7557ba 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -104,9 +104,9 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) satellite.setSteps(chamfer_steps); subpath_satellites.push_back(satellite); } - //we add the last satellite on open path because pointwise is related to nodes, not curves + //we add the last satellite on open path because pathVectorSatellites is related to nodes, not curves //so maybe in the future we can need this last satellite in other effects - //dont remove for this effect because pointwise class has methods when the path is modiffied + //dont remove for this effect because pathVectorSatellites class has methods when the path is modiffied //and we want one method for all uses if (!path_it->closed()) { Satellite satellite(FILLET); @@ -115,9 +115,9 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } satellites.push_back(subpath_satellites); } - pointwise.setPathVector(pathv); - pointwise.setSatellites(satellites); - satellites_param.setPointwise(pointwise); + pathVectorSatellites.setPathVector(pathv); + pathVectorSatellites.setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathVectorSatellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem *item = const_cast(lpeItem); @@ -256,8 +256,8 @@ void LPEFilletChamfer::updateAmount() } else { power = radius / 100; } - Satellites satellites = pointwise.getSatellites(); - Geom::PathVector pathv = pointwise.getPathVector(); + Satellites satellites = pathVectorSatellites.getSatellites(); + Geom::PathVector pathv = pathVectorSatellites.getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { boost::optional previous_index = boost::none; @@ -293,14 +293,14 @@ void LPEFilletChamfer::updateAmount() } } } - pointwise.setSatellites(satellites); - satellites_param.setPointwise(pointwise); + pathVectorSatellites.setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathVectorSatellites); } void LPEFilletChamfer::updateChamferSteps() { - Satellites satellites = pointwise.getSatellites(); - Geom::PathVector pathv = pointwise.getPathVector(); + Satellites satellites = pathVectorSatellites.getSatellites(); + Geom::PathVector pathv = pathVectorSatellites.getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if ((!apply_no_radius && satellites[i][j].amount == 0) || @@ -318,14 +318,14 @@ void LPEFilletChamfer::updateChamferSteps() } } } - pointwise.setSatellites(satellites); - satellites_param.setPointwise(pointwise); + pathVectorSatellites.setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathVectorSatellites); } void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - Satellites satellites = pointwise.getSatellites(); - Geom::PathVector pathv = pointwise.getPathVector(); + Satellites satellites = pathVectorSatellites.getSatellites(); + Geom::PathVector pathv = pathVectorSatellites.getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if ((!apply_no_radius && satellites[i][j].amount == 0) || @@ -349,8 +349,8 @@ void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) } } } - pointwise.setSatellites(satellites); - satellites_param.setPointwise(pointwise); + pathVectorSatellites.setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathVectorSatellites); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -371,14 +371,14 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 size_t number_nodes = pathv.nodes().size(); - size_t satellites_counter = pointwise.getTotalSatellites(); + size_t satellites_counter = pathVectorSatellites.getTotalSatellites(); if (satellites_counter != 0 && number_nodes != satellites_counter) { Satellite satellite(FILLET); satellite.setIsTime(flexible); satellite.setHasMirror(mirror_knots); satellite.setHidden(hide_knots); - pointwise.recalculateForNewPathVector(pathv, satellite); - satellites_param.setPointwise(pointwise); + pathVectorSatellites.recalculateForNewPathVector(pathv, satellite); + satellites_param.setPathVectorSatellites(pathVectorSatellites); refreshKnots(); return; } @@ -416,9 +416,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } } - pointwise.setPathVector(pathv); - pointwise.setSatellites(satellites); - satellites_param.setPointwise(pointwise); + pathVectorSatellites.setPathVector(pathv); + pathVectorSatellites.setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathVectorSatellites); refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); @@ -454,7 +454,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } double time0 = 0; size_t curve = 0; - Satellites satellites = pointwise.getSatellites(); + Satellites satellites = pathVectorSatellites.getSatellites(); for (Geom::Path::const_iterator curve_it1 = path_it->begin(); curve_it1 != path_it->end(); ++curve_it1) { size_t next_index = curve + 1; if (curve == pathv[path].size() - 1 && pathv[path].closed()) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 7603c7de4..62b894660 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -15,7 +15,7 @@ #include "live_effects/parameter/enum.h" #include "live_effects/parameter/satellitesarray.h" #include "live_effects/effect.h" -#include "helper/geom-pointwise.h" +#include "helper/geom-pathvectorsatellites.h" namespace Inkscape { namespace LivePathEffect { @@ -60,7 +60,7 @@ private: BoolParam apply_with_radius; ScalarParam helper_size; - Pointwise pointwise; + PathVectorSatellites pathVectorSatellites; Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 78f1a945f..45a6282e0 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -44,10 +44,10 @@ void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, _knot_color = color; } -void SatellitesArrayParam::setPointwise(Pointwise pointwise) +void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites pathVectorSatellites) { - _last_pointwise = pointwise; - param_set_and_write_new_value(_last_pointwise.getSatellites()); + _last_pathVectorSatellites = pathVectorSatellites; + param_set_and_write_new_value(_last_pathVectorSatellites.getSatellites()); } @@ -68,13 +68,13 @@ void SatellitesArrayParam::setHelperSize(int hs) } bool SatellitesArrayParam::validData(size_t index,size_t subindex) { - if(!_last_pointwise.getPathVector().size() > index){ + if(!_last_pathVectorSatellites.getPathVector().size() > index){ return false; } - if(!_last_pointwise.getPathVector()[index].size_closed() > subindex){ + if(!_last_pathVectorSatellites.getPathVector()[index].size_closed() > subindex){ return false; } - return true; //_last_pointwise.getPathVector().nodes().size() == _last_pointwise.getTotalSatellites(); + return true; //_last_pathVectorSatellites.getPathVector().nodes().size() == _last_pathVectorSatellites.getTotalSatellites(); } void SatellitesArrayParam::updateCanvasIndicators(bool mirror) @@ -83,7 +83,7 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) if(!_hp.empty()) { _hp.clear(); } - Geom::PathVector pathv = _last_pointwise.getPathVector(); + Geom::PathVector pathv = _last_pathVectorSatellites.getPathVector(); if (pathv.empty()) { return; } @@ -218,7 +218,7 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror) { - Geom::PathVector pathv = _last_pointwise.getPathVector(); + Geom::PathVector pathv = _last_pathVectorSatellites.getPathVector(); for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { if (!validData(i, j)) { @@ -293,7 +293,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, return; } Satellite satellite = _pparam->_vector[_index][subindex]; - Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); if (satellite.hidden || !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect @@ -308,7 +308,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Curve const &curve_in = pathv[_index][previous_index]; double mirror_time = Geom::nearest_time(s, curve_in); double time_start = 0; - Satellites satellites = _pparam->_last_pointwise.getSatellites(); + Satellites satellites = _pparam->_last_pathVectorSatellites.getSatellites(); time_start = satellites[_index][previous_index].time(curve_in); if (time_start > mirror_time) { mirror_time = time_start; @@ -341,7 +341,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const return Geom::Point(Geom::infinity(), Geom::infinity()); } Satellite satellite = _pparam->_vector[_index][subindex]; - Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); if (satellite.hidden || !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect @@ -368,7 +368,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const t = 0; } double time_start = 0; - time_start = _pparam->_last_pointwise.getSatellites()[_index][previous_index].time(curve_in); + time_start = _pparam->_last_pathVectorSatellites.getSatellites()[_index][previous_index].time(curve_in); if (time_start > t) { t = time_start; } @@ -389,7 +389,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) if (!_pparam->validData(_index, subindex)) { return; } - Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); if (!pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect { @@ -480,7 +480,7 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) if (!_pparam->validData(_index, subindex)) { return; } - Geom::PathVector pathv = _pparam->_last_pointwise.getPathVector(); + Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); if (satellite.hidden || !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index c6893f595..27e9dea6f 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -12,7 +12,7 @@ * hours * * - * This parameter act as bridge from pointwise class to serialize it as a LPE + * This parameter act as bridge from pathVectorSatellites class to serialize it as a LPE * parameter * * Released under GNU GPL, read the file 'COPYING' for more information @@ -20,7 +20,7 @@ #include "live_effects/parameter/array.h" #include "live_effects/effect-enum.h" -#include "helper/geom-pointwise.h" +#include "helper/geom-pathvectorsatellites.h" #include "knot-holder-entity.h" #include @@ -56,7 +56,7 @@ public: void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); void setEffectType(EffectType et); - void setPointwise(Pointwise pointwise); + void setPathVectorSatellites(PathVectorSatellites pathVectorSatellites); bool validData(size_t index, size_t subindex); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); @@ -77,7 +77,7 @@ private: int _helper_size; bool _use_distance; EffectType _effectType; - Pointwise _last_pointwise; + PathVectorSatellites _last_pathVectorSatellites; }; -- cgit v1.2.3 From 5ad260d5810f6f8bb2cdea7186d0766091ad9b54 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 11 Jun 2016 17:32:56 +0200 Subject: Fixing satellites bug on erase (bzr r13645.1.146) --- src/live_effects/lpe-fillet-chamfer.cpp | 3 +-- src/live_effects/parameter/satellitesarray.cpp | 19 +++++++++++++++++-- src/live_effects/parameter/satellitesarray.h | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 56f7557ba..b4eca6909 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -378,8 +378,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellite.setHasMirror(mirror_knots); satellite.setHidden(hide_knots); pathVectorSatellites.recalculateForNewPathVector(pathv, satellite); - satellites_param.setPathVectorSatellites(pathVectorSatellites); - refreshKnots(); + satellites_param.setPathVectorSatellites(pathVectorSatellites, true); return; } Satellites satellites = satellites_param.data(); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 45a6282e0..cb7d0df8f 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -44,11 +44,16 @@ void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, _knot_color = color; } -void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites pathVectorSatellites) +void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites pathVectorSatellites, bool refresh_knots) { + if (refresh_knots) { + clearKnotHolder(knoth); + } _last_pathVectorSatellites = pathVectorSatellites; param_set_and_write_new_value(_last_pathVectorSatellites.getSatellites()); - + if (refresh_knots) { + addKnotHolderEntities(knoth, SP_ACTIVE_DESKTOP, knoth.getItem()); + } } void SatellitesArrayParam::setUseDistance(bool use_knot_distance) @@ -214,6 +219,16 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, } } +void SatellitesArrayParam::clearKnotHolder(KnotHolder *knotholder) +{ + for (std::list::iterator i = knotholder.entity.begin(); i != knotholder.entity.end(); ++i) + { + delete (*i); + (*i) = NULL; + } + entity.clear(); // is this necessary? +} + void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror) diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index 27e9dea6f..c52d28541 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -45,6 +45,7 @@ public: SPItem *item); virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror); + virtual void clearKnotHolder(KnotHolder *knotholder); virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); virtual void updateCanvasIndicators(); @@ -56,7 +57,7 @@ public: void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); void setEffectType(EffectType et); - void setPathVectorSatellites(PathVectorSatellites pathVectorSatellites); + void setPathVectorSatellites(PathVectorSatellites pathVectorSatellites, bool refresh_knots = false); bool validData(size_t index, size_t subindex); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); -- cgit v1.2.3 From d84bbca17771ed1a2f680328adf14b30a4c66b77 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 01:05:25 +0200 Subject: Fix the bug deleting satellites (bzr r13645.1.148) --- src/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 +- src/live_effects/parameter/satellitesarray.cpp | 248 +++++++++++++------------ src/live_effects/parameter/satellitesarray.h | 13 +- 7 files changed, 192 insertions(+), 172 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index a5207ab00..c423c9b1b 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 72ecef38f..483611db5 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 f1bacebe5..c8136da3f 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 b4eca6909..1d5c036ba 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,9 +16,9 @@ #include <2geom/elliptical-arc.h> #include "knotholder.h" #include -#include "ui/tools-switch.h" // TODO due to internal breakage in glibmm headers, this must be last: #include + namespace Inkscape { namespace LivePathEffect { @@ -54,7 +54,8 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) apply_no_radius(_("Apply changes if radius = 0"), _("Apply changes if radius = 0"), "apply_no_radius", &wr, this, true), apply_with_radius(_("Apply changes if radius > 0"), _("Apply changes if radius > 0"), "apply_with_radius", &wr, this, true), helper_size(_("Helper size with direction:"), - _("Helper size with direction"), "helper_size", &wr, this, 0) + _("Helper size with direction"), "helper_size", &wr, this, 0), + pathvector_satellites(NULL) { registerParameter(&satellites_param); registerParameter(&method); @@ -104,9 +105,9 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) satellite.setSteps(chamfer_steps); subpath_satellites.push_back(satellite); } - //we add the last satellite on open path because pathVectorSatellites is related to nodes, not curves + //we add the last satellite on open path because pathvector_satellites is related to nodes, not curves //so maybe in the future we can need this last satellite in other effects - //dont remove for this effect because pathVectorSatellites class has methods when the path is modiffied + //dont remove for this effect because pathvector_satellites class has methods when the path is modiffied //and we want one method for all uses if (!path_it->closed()) { Satellite satellite(FILLET); @@ -115,9 +116,10 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } satellites.push_back(subpath_satellites); } - pathVectorSatellites.setPathVector(pathv); - pathVectorSatellites.setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathVectorSatellites); + pathvector_satellites = new PathVectorSatellites(); + pathvector_satellites->setPathVector(pathv); + pathvector_satellites->setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathvector_satellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem *item = const_cast(lpeItem); @@ -239,12 +241,8 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - //Find another way to update knots satellites_param.knoth->update_knots(); do the thing - //but not updat the knot index on node delete - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (tools_isactive(desktop, TOOLS_NODES)) { - tools_switch(desktop, TOOLS_SELECT); - tools_switch(desktop, TOOLS_NODES); + if (satellites_param.knoth) { + satellites_param.knoth->update_knots(); } } @@ -256,8 +254,8 @@ void LPEFilletChamfer::updateAmount() } else { power = radius / 100; } - Satellites satellites = pathVectorSatellites.getSatellites(); - Geom::PathVector pathv = pathVectorSatellites.getPathVector(); + Satellites satellites = pathvector_satellites->getSatellites(); + Geom::PathVector pathv = pathvector_satellites->getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { boost::optional previous_index = boost::none; @@ -293,14 +291,14 @@ void LPEFilletChamfer::updateAmount() } } } - pathVectorSatellites.setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathVectorSatellites); + pathvector_satellites->setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathvector_satellites); } void LPEFilletChamfer::updateChamferSteps() { - Satellites satellites = pathVectorSatellites.getSatellites(); - Geom::PathVector pathv = pathVectorSatellites.getPathVector(); + Satellites satellites = pathvector_satellites->getSatellites(); + Geom::PathVector pathv = pathvector_satellites->getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if ((!apply_no_radius && satellites[i][j].amount == 0) || @@ -318,14 +316,14 @@ void LPEFilletChamfer::updateChamferSteps() } } } - pathVectorSatellites.setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathVectorSatellites); + pathvector_satellites->setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathvector_satellites); } void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - Satellites satellites = pathVectorSatellites.getSatellites(); - Geom::PathVector pathv = pathVectorSatellites.getPathVector(); + Satellites satellites = pathvector_satellites->getSatellites(); + Geom::PathVector pathv = pathvector_satellites->getPathVector(); for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { if ((!apply_no_radius && satellites[i][j].amount == 0) || @@ -349,8 +347,8 @@ void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) } } } - pathVectorSatellites.setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathVectorSatellites); + pathvector_satellites->setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathvector_satellites); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -370,16 +368,19 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 - size_t number_nodes = pathv.nodes().size(); - size_t satellites_counter = pathVectorSatellites.getTotalSatellites(); - if (satellites_counter != 0 && number_nodes != satellites_counter) { - Satellite satellite(FILLET); - satellite.setIsTime(flexible); - satellite.setHasMirror(mirror_knots); - satellite.setHidden(hide_knots); - pathVectorSatellites.recalculateForNewPathVector(pathv, satellite); - satellites_param.setPathVectorSatellites(pathVectorSatellites, true); - return; + if (pathvector_satellites) { + size_t number_nodes = pathv.nodes().size(); + size_t satellites_counter = pathvector_satellites->getTotalSatellites(); + if (number_nodes != satellites_counter) { + Satellite satellite(FILLET); + satellite.setIsTime(flexible); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hide_knots); + pathvector_satellites->recalculateForNewPathVector(pathv, satellite); + satellites_param.setPathVectorSatellites(pathvector_satellites); + refreshKnots(); + return; + } } Satellites satellites = satellites_param.data(); if(satellites.empty()) { @@ -414,10 +415,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].hidden = hide_knots; } } - - pathVectorSatellites.setPathVector(pathv); - pathVectorSatellites.setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathVectorSatellites); + pathvector_satellites = new PathVectorSatellites(); + pathvector_satellites->setPathVector(pathv); + pathvector_satellites->setSatellites(satellites); + satellites_param.setPathVectorSatellites(pathvector_satellites); refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); @@ -442,7 +443,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (path_it->empty()) { continue; } - _hp.push_back(*path_it); Geom::Path tmp_path; if (path_it->size() == 1) { path++; @@ -453,7 +453,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } double time0 = 0; size_t curve = 0; - Satellites satellites = pathVectorSatellites.getSatellites(); + Satellites satellites = pathvector_satellites->getSatellites(); for (Geom::Path::const_iterator curve_it1 = path_it->begin(); curve_it1 != path_it->end(); ++curve_it1) { size_t next_index = curve + 1; if (curve == pathv[path].size() - 1 && pathv[path].closed()) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 62b894660..363a35d43 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -60,7 +60,7 @@ private: BoolParam apply_with_radius; ScalarParam helper_size; - PathVectorSatellites pathVectorSatellites; + PathVectorSatellites *pathvector_satellites; Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index cb7d0df8f..e61aaf38d 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -11,6 +11,7 @@ #include "live_effects/parameter/satellitesarray.h" #include "live_effects/effect.h" #include "sp-lpe-item.h" +#include "inkscape.h" #include // TODO due to internal breakage in glibmm headers, // this has to be included last. @@ -33,6 +34,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, _helper_size = 0; _use_distance = false; _effectType = FILLET_CHAMFER; + _last_pathvector_satellites = NULL; } void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, @@ -44,16 +46,10 @@ void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, _knot_color = color; } -void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites pathVectorSatellites, bool refresh_knots) +void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites) { - if (refresh_knots) { - clearKnotHolder(knoth); - } - _last_pathVectorSatellites = pathVectorSatellites; - param_set_and_write_new_value(_last_pathVectorSatellites.getSatellites()); - if (refresh_knots) { - addKnotHolderEntities(knoth, SP_ACTIVE_DESKTOP, knoth.getItem()); - } + _last_pathvector_satellites = pathVectorSatellites; + param_set_and_write_new_value(_last_pathvector_satellites->getSatellites()); } void SatellitesArrayParam::setUseDistance(bool use_knot_distance) @@ -71,24 +67,18 @@ void SatellitesArrayParam::setHelperSize(int hs) _helper_size = hs; updateCanvasIndicators(); } -bool SatellitesArrayParam::validData(size_t index,size_t subindex) -{ - if(!_last_pathVectorSatellites.getPathVector().size() > index){ - return false; - } - if(!_last_pathVectorSatellites.getPathVector()[index].size_closed() > subindex){ - return false; - } - return true; //_last_pathVectorSatellites.getPathVector().nodes().size() == _last_pathVectorSatellites.getTotalSatellites(); -} void SatellitesArrayParam::updateCanvasIndicators(bool mirror) { + if (!_last_pathvector_satellites) { + return; + } + if(!_hp.empty()) { _hp.clear(); } - Geom::PathVector pathv = _last_pathVectorSatellites.getPathVector(); + Geom::PathVector pathv = _last_pathvector_satellites->getPathVector(); if (pathv.empty()) { return; } @@ -98,9 +88,6 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) if (_effectType == FILLET_CHAMFER) { for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { - if (!validData(i, j)) { - return; - } if (_vector[i][j].hidden || //Ignore if hidden (!_vector[i][j].has_mirror && mirror == true) || //Ignore if not have mirror and we are in mirror loop _vector[i][j].amount == 0 || //no helper in 0 value @@ -219,41 +206,28 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, } } -void SatellitesArrayParam::clearKnotHolder(KnotHolder *knotholder) -{ - for (std::list::iterator i = knotholder.entity.begin(); i != knotholder.entity.end(); ++i) - { - delete (*i); - (*i) = NULL; - } - entity.clear(); // is this necessary? -} - void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item, bool mirror) + SPItem *item, + bool mirror) { - Geom::PathVector pathv = _last_pathVectorSatellites.getPathVector(); + Geom::PathVector pathv = _last_pathvector_satellites->getPathVector(); + size_t index = 0; for (size_t i = 0; i < _vector.size(); ++i) { for (size_t j = 0; j < _vector[i].size(); ++j) { - if (!validData(i, j)) { - return; - } if (!_vector[i][j].has_mirror && mirror) { continue; } SatelliteType type = _vector[i][j].satellite_type; - size_t index = i; - size_t subindex = j; - if (mirror) { - subindex = subindex + _vector[i].size(); + if (mirror && i == 0 && j == 0) { + index = index + _last_pathvector_satellites->getTotalSatellites(); } using namespace Geom; //If is for filletChamfer effect... if (_effectType == FILLET_CHAMFER) { - if(!pathv[i].closed() && (j == 0 || j == _vector[i].size() -1)) { - continue; - } +// if(!pathv[i].closed() && (j == 0 || j == _vector[i].size() -1)) { +// continue; +// } const gchar *tip; if (type == CHAMFER) { tip = _("Chamfer: Ctrl+Click toggle type, " @@ -272,10 +246,11 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } - FilletChamferKnotHolderEntity *e = new FilletChamferKnotHolderEntity(this, index, subindex); + FilletChamferKnotHolderEntity *e = new FilletChamferKnotHolderEntity(this, index); e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip),_knot_shape, _knot_mode, _knot_color); knotholder->add(e); } + index++; } } if (mirror) { @@ -292,52 +267,62 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, } FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( - SatellitesArrayParam *p, size_t index, size_t subindex) - : _pparam(p), _index(index), _subindex(subindex) {} + SatellitesArrayParam *p, size_t index) + : _pparam(p), _index(index) {} void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) { - Geom::Point s = snap_knot_position(p, state); - size_t subindex = _subindex; - if (_subindex >= _pparam->_vector[_index].size()) { - subindex = _subindex - _pparam->_vector[_index].size(); + if (!_pparam->_last_pathvector_satellites) { + return; + } + size_t total_satellites = _pparam->_last_pathvector_satellites->getTotalSatellites(); + bool is_mirror = false; + size_t index = _index; + if (_index >= total_satellites) { + index = _index - total_satellites; + is_mirror = true; } - if (!_pparam->validData(_index, subindex)) { + std::pair index_data = _pparam->_last_pathvector_satellites->getIndexData(index); + size_t path_index = index_data.first; + size_t curve_index = index_data.second; + + Geom::Point s = snap_knot_position(p, state); + if (!valid_index(path_index, curve_index)) { return; } - Satellite satellite = _pparam->_vector[_index][subindex]; - Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); + Satellite satellite = _pparam->_vector[path_index][curve_index]; + Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); if (satellite.hidden || - !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths - pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + !pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return; } - if (subindex != _subindex) { - size_t previous_index = subindex - 1; - if(subindex == 0 && pathv[_index].closed()){ - previous_index = pathv[_index].size() - 1; + if (is_mirror) { + size_t previous_index = curve_index - 1; + if(curve_index == 0 && pathv[path_index].closed()){ + previous_index = pathv[path_index].size() - 1; } - Geom::Curve const &curve_in = pathv[_index][previous_index]; + Geom::Curve const &curve_in = pathv[path_index][previous_index]; double mirror_time = Geom::nearest_time(s, curve_in); double time_start = 0; - Satellites satellites = _pparam->_last_pathVectorSatellites.getSatellites(); - time_start = satellites[_index][previous_index].time(curve_in); + Satellites satellites = _pparam->_last_pathvector_satellites->getSatellites(); + time_start = satellites[path_index][previous_index].time(curve_in); if (time_start > mirror_time) { mirror_time = time_start; } double size = arcLengthAt(mirror_time, curve_in); double amount = curve_in.length() - size; if (satellite.is_time) { - amount = timeAtArcLength(amount, pathv[_index][subindex]); + amount = timeAtArcLength(amount, pathv[path_index][curve_index]); } satellite.amount = amount; } else { - satellite.setPosition(s, pathv[_index][subindex]); + satellite.setPosition(s, pathv[path_index][curve_index]); } - _pparam->_vector[_index][subindex] = satellite; + _pparam->_vector[path_index][curve_index] = satellite; SPLPEItem *splpeitem = dynamic_cast(item); if (splpeitem) { sp_lpe_item_update_patheffect(splpeitem, false, false); @@ -346,35 +331,40 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point FilletChamferKnotHolderEntity::knot_get() const { + if (!_pparam->_last_pathvector_satellites) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } Geom::Point tmp_point; - size_t subindex = _subindex; - if (_subindex >= _pparam->_vector[_index].size()) { - subindex = _subindex - _pparam->_vector[_index].size(); + size_t total_satellites = _pparam->_last_pathvector_satellites->getTotalSatellites(); + bool is_mirror = false; + size_t index = _index; + if (_index >= total_satellites) { + index = _index - total_satellites; + is_mirror = true; } - if (!_pparam->validData(_index, subindex)) { - this->knot->hide(); + std::pair index_data = _pparam->_last_pathvector_satellites->getIndexData(index); + size_t path_index = index_data.first; + size_t curve_index = index_data.second; + if (!valid_index(path_index, curve_index)) { return Geom::Point(Geom::infinity(), Geom::infinity()); } - Satellite satellite = _pparam->_vector[_index][subindex]; - Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); + Satellite satellite = _pparam->_vector[path_index][curve_index]; + Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); if (satellite.hidden || - !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths - pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + !pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { - this->knot->hide(); - _pparam->_vector[_index][subindex].hidden = true; return Geom::Point(Geom::infinity(), Geom::infinity()); } this->knot->show(); - std::cout << subindex << pathv[_index].size() << "----" << _pparam->_vector[_index].size() << "fgdgsdgsdgsdsdsgd\n"; - if (subindex != _subindex) { - tmp_point = satellite.getPosition(pathv[_index][subindex]); - size_t previous_index = subindex - 1; - if(subindex == 0 && pathv[_index].closed()){ - previous_index = pathv[_index].size() - 1; + if (is_mirror) { + tmp_point = satellite.getPosition(pathv[path_index][curve_index]); + size_t previous_index = curve_index - 1; + if(curve_index == 0 && pathv[path_index].closed()){ + previous_index = pathv[path_index].size() - 1; } - Geom::Curve const &curve_in = pathv[_index][previous_index]; - double s = satellite.arcDistance(pathv[_index][subindex]); + Geom::Curve const &curve_in = pathv[path_index][previous_index]; + double s = satellite.arcDistance(pathv[path_index][curve_index]); double t = satellite.time(s, true, curve_in); if (t > 1) { t = 1; @@ -383,13 +373,13 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const t = 0; } double time_start = 0; - time_start = _pparam->_last_pathVectorSatellites.getSatellites()[_index][previous_index].time(curve_in); + time_start = _pparam->_last_pathvector_satellites->getSatellites()[path_index][previous_index].time(curve_in); if (time_start > t) { t = time_start; } tmp_point = (curve_in).pointAt(t); } else { - tmp_point = satellite.getPosition(pathv[_index][subindex]); + tmp_point = satellite.getPosition(pathv[path_index][curve_index]); } Geom::Point const canvas_point = tmp_point; return canvas_point; @@ -397,27 +387,36 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const void FilletChamferKnotHolderEntity::knot_click(guint state) { - size_t subindex = _subindex; - if (_subindex >= _pparam->_vector[_index].size()) { - subindex = _subindex - _pparam->_vector[_index].size(); + if (!_pparam->_last_pathvector_satellites) { + return; } - if (!_pparam->validData(_index, subindex)) { + size_t total_satellites = _pparam->_last_pathvector_satellites->getTotalSatellites(); + bool is_mirror = false; + size_t index = _index; + if (_index >= total_satellites) { + index = _index - total_satellites; + is_mirror = true; + } + std::pair index_data = _pparam->_last_pathvector_satellites->getIndexData(index); + size_t path_index = index_data.first; + size_t curve_index = index_data.second; + if (!valid_index(path_index, curve_index)) { return; } - Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); - if (!pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths - pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); + if (!pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return; } if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { - _pparam->_vector[_index][subindex].amount = 0.0; + _pparam->_vector[path_index][curve_index].amount = 0.0; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); } else { using namespace Geom; - SatelliteType type = _pparam->_vector[_index][subindex].satellite_type; + SatelliteType type = _pparam->_vector[path_index][curve_index].satellite_type; switch (type) { case FILLET: type = INVERSE_FILLET; @@ -432,7 +431,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) type = FILLET; break; } - _pparam->_vector[_index][subindex].satellite_type = type; + _pparam->_vector[path_index][curve_index].satellite_type = type; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); const gchar *tip; @@ -457,22 +456,22 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - double amount = _pparam->_vector[_index][subindex].amount; - size_t previous_index = subindex - 1; - if(subindex == 0 && pathv[_index].closed()){ - previous_index = pathv[_index].size() - 1; + double amount = _pparam->_vector[path_index][curve_index].amount; + size_t previous_index = curve_index - 1; + if(curve_index == 0 && pathv[path_index].closed()){ + previous_index = pathv[path_index].size() - 1; } - if (!_pparam->_use_distance && !_pparam->_vector[_index][subindex].is_time) { + if (!_pparam->_use_distance && !_pparam->_vector[path_index][curve_index].is_time) { if (previous_index) { - amount = _pparam->_vector[_index][subindex].lenToRad(amount, pathv[_index][previous_index], pathv[_index][subindex], _pparam->_vector[_index][previous_index]); + amount = _pparam->_vector[path_index][curve_index].lenToRad(amount, pathv[path_index][previous_index], pathv[path_index][curve_index], _pparam->_vector[path_index][previous_index]); } else { amount = 0.0; } } bool aprox = false; - Geom::D2 d2_out = pathv[_index][subindex].toSBasis(); + Geom::D2 d2_out = pathv[path_index][curve_index].toSBasis(); if (previous_index) { - Geom::D2 d2_in = pathv[_index][previous_index].toSBasis(); + Geom::D2 d2_in = pathv[path_index][previous_index].toSBasis(); aprox = ((d2_in)[0].degreesOfFreedom() != 2 || d2_out[0].degreesOfFreedom() != 2) && !_pparam->_use_distance @@ -481,41 +480,50 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( this->desktop, amount, this, _pparam->_use_distance, - aprox, _pparam->_vector[_index][subindex]); + aprox, _pparam->_vector[path_index][curve_index]); } } void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) { - size_t subindex = _subindex; - if (_subindex >= _pparam->_vector[_index].size()) { - subindex = _subindex - _pparam->_vector[_index].size(); + if (!_pparam->_last_pathvector_satellites) { + return; + } + size_t total_satellites = _pparam->_last_pathvector_satellites->getTotalSatellites(); + bool is_mirror = false; + size_t index = _index; + if (_index >= total_satellites) { + index = _index - total_satellites; + is_mirror = true; } - if (!_pparam->validData(_index, subindex)) { + std::pair index_data = _pparam->_last_pathvector_satellites->getIndexData(index); + size_t path_index = index_data.first; + size_t curve_index = index_data.second; + if (!valid_index(path_index, curve_index)) { return; } - Geom::PathVector pathv = _pparam->_last_pathVectorSatellites.getPathVector(); + Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); if (satellite.hidden || - !pathv[_index].closed() && subindex == 0 ||//ignore first satellites on open paths - pathv[_index].size() == subindex) //ignore last satellite in open paths with fillet chamfer effect + !pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return; } double amount = satellite.amount; double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { - size_t previous_index = subindex - 1; - if(subindex == 0 && pathv[_index].closed()){ - previous_index = pathv[_index].size() - 1; + size_t previous_index = curve_index - 1; + if(curve_index == 0 && pathv[path_index].closed()){ + previous_index = pathv[path_index].size() - 1; } - amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][previous_index], pathv[_index][subindex]); + amount = _pparam->_vector[path_index][curve_index].radToLen(amount, pathv[path_index][previous_index], pathv[path_index][curve_index]); if (max_amount > 0 && amount == 0) { - amount = _pparam->_vector[_index][subindex].amount; + amount = _pparam->_vector[path_index][curve_index].amount; } } satellite.amount = amount; - _pparam->_vector[_index][subindex] = satellite; + _pparam->_vector[path_index][curve_index] = satellite; this->parent_holder->knot_ungrabbed_handler(this->knot, 0); _pparam->param_set_and_write_new_value(_pparam->_vector); SPLPEItem *splpeitem = dynamic_cast(item); diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index c52d28541..a52bcef53 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -45,7 +45,6 @@ public: SPItem *item); virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror); - virtual void clearKnotHolder(KnotHolder *knotholder); virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); virtual void updateCanvasIndicators(); @@ -57,8 +56,7 @@ public: void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); void setEffectType(EffectType et); - void setPathVectorSatellites(PathVectorSatellites pathVectorSatellites, bool refresh_knots = false); - bool validData(size_t index, size_t subindex); + void setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); friend class FilletChamferKnotHolderEntity; @@ -78,13 +76,13 @@ private: int _helper_size; bool _use_distance; EffectType _effectType; - PathVectorSatellites _last_pathVectorSatellites; + PathVectorSatellites *_last_pathvector_satellites; }; class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: - FilletChamferKnotHolderEntity(SatellitesArrayParam *p, size_t index, size_t subindex); + FilletChamferKnotHolderEntity(SatellitesArrayParam *p, size_t index); virtual ~FilletChamferKnotHolderEntity() { _pparam->knoth = NULL; @@ -97,15 +95,14 @@ public: void knot_set_offset(Satellite); /** Checks whether the index falls within the size of the parameter's vector */ - bool valid_index(size_t index) const + bool valid_index(size_t index,size_t subindex) const { - return (_pparam->_vector.size() > index); + return (_pparam->_vector.size() > index && _pparam->_vector[index].size() > subindex); }; private: SatellitesArrayParam *_pparam; size_t _index; - size_t _subindex; }; } //namespace LivePathEffect -- cgit v1.2.3 From 1b8a4e46125f60f7bbe497bde69a11b7b3153b00 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 12:09:57 +0200 Subject: Handle path add and remove nodes (bzr r13645.1.150) --- src/helper/geom-pathvectorsatellites.cpp | 40 ++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index c423c9b1b..625506b2f 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); -- cgit v1.2.3 From 7e1183de6ed51ff730915fe936e2bb607dd72f33 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 16:33:27 +0200 Subject: Fix bug consecutive nodes at same position (bzr r13645.1.152) --- src/live_effects/lpe-fillet-chamfer.cpp | 14 +++++++++++++- src/live_effects/lpe-fillet-chamfer.h | 1 + src/live_effects/parameter/satellitesarray.cpp | 7 ++++++- src/live_effects/parameter/satellitesarray.h | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 1d5c036ba..48e68d366 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -55,7 +55,8 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) apply_with_radius(_("Apply changes if radius > 0"), _("Apply changes if radius > 0"), "apply_with_radius", &wr, this, true), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pathvector_satellites(NULL) + pathvector_satellites(NULL), + degenerate_hide(false) { registerParameter(&satellites_param); registerParameter(&method); @@ -387,6 +388,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) doOnApply(lpeItem); satellites = satellites_param.data(); } + if (degenerate_hide) { + satellites_param.setGlobalKnotHide(true); + } else { + satellites_param.setGlobalKnotHide(false); + } if (hide_knots) { satellites_param.setHelperSize(0); } else { @@ -438,6 +444,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::PathVector path_out; size_t path = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); + degenerate_hide = false; Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { if (path_it->empty()) { @@ -468,6 +475,11 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) continue; } Satellite satellite = satellites[path][next_index]; + if (Geom::are_near((*curve_it1).initialPoint(),(*curve_it1).finalPoint())) { + degenerate_hide = true; + g_warning("Knots hidded if consecutive nodes has the same position."); + return path_in; + } if (!curve) { //curve == 0 if (!path_it->closed()) { time0 = 0; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 363a35d43..420403b70 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -60,6 +60,7 @@ private: BoolParam apply_with_radius; ScalarParam helper_size; + bool degenerate_hide; PathVectorSatellites *pathvector_satellites; Geom::PathVector _hp; diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index e61aaf38d..db7cf80c0 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -33,6 +33,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, _knot_color = 0xAAFF8800; _helper_size = 0; _use_distance = false; + _global_knot_hide = false; _effectType = FILLET_CHAMFER; _last_pathvector_satellites = NULL; } @@ -57,6 +58,10 @@ void SatellitesArrayParam::setUseDistance(bool use_knot_distance) _use_distance = use_knot_distance; } +void SatellitesArrayParam::setGlobalKnotHide(bool global_knot_hide) +{ + _global_knot_hide = global_knot_hide; +} void SatellitesArrayParam::setEffectType(EffectType et) { _effectType = et; @@ -331,7 +336,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point FilletChamferKnotHolderEntity::knot_get() const { - if (!_pparam->_last_pathvector_satellites) { + if (!_pparam->_last_pathvector_satellites || _pparam->_global_knot_hide) { return Geom::Point(Geom::infinity(), Geom::infinity()); } Geom::Point tmp_point; diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index a52bcef53..30b1db6c1 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -55,6 +55,7 @@ public: } void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); + void setGlobalKnotHide(bool global_knot_hide); void setEffectType(EffectType et); void setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); @@ -75,6 +76,7 @@ private: Geom::PathVector _hp; int _helper_size; bool _use_distance; + bool _global_knot_hide; EffectType _effectType; PathVectorSatellites *_last_pathvector_satellites; -- cgit v1.2.3 From e40990e3b9c391cdded31f28bb8f8d448fd1d361 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 17:27:07 +0200 Subject: Handle both directions on knot reposition (bzr r13645.1.154) --- src/live_effects/parameter/satellitesarray.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index db7cf80c0..18e1bd4de 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -305,13 +305,18 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, { return; } - if (is_mirror) { - size_t previous_index = curve_index - 1; - if(curve_index == 0 && pathv[path_index].closed()){ - previous_index = pathv[path_index].size() - 1; - } - Geom::Curve const &curve_in = pathv[path_index][previous_index]; - double mirror_time = Geom::nearest_time(s, curve_in); + size_t previous_index = curve_index - 1; + if(curve_index == 0 && pathv[path_index].closed()){ + previous_index = pathv[path_index].size() - 1; + } + Geom::Curve const &curve_in = pathv[path_index][previous_index]; + double mirror_time = Geom::nearest_time(s, curve_in); + Geom::Point mirror = curve_in.pointAt(mirror_time); + double normal_time = Geom::nearest_time(s, pathv[path_index][curve_index]); + Geom::Point normal = pathv[path_index][curve_index].pointAt(normal_time); + double distance_mirror = Geom::distance(mirror,s); + double distance_normal = Geom::distance(normal,s); + if (distance_mirror <= distance_normal) { double time_start = 0; Satellites satellites = _pparam->_last_pathvector_satellites->getSatellites(); time_start = satellites[path_index][previous_index].time(curve_in); -- cgit v1.2.3 From 73f078b27b669c941651ecf14a3119ae491ccabf Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 13 Jun 2016 00:58:55 +0200 Subject: Fix 90% of tweenk review (bzr r13645.1.155) --- src/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 + src/live_effects/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(-) (limited to 'src') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index 625506b2f..c56887f53 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 483611db5..4a020f553 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 2672a571b..1242c9aaf 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 6cf891ec5..a4d63d66e 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 0a78b199e..f60d628f6 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -400,19 +400,39 @@ Effect::doOnApply (SPLPEItem const*/*lpeitem*/) } void -Effect::setSelectedNodePoints(std::vector sNP) +Effect::setCurrentZoom(double cZ) { - selectedNodesPoints = sNP; + current_zoom = cZ; } void -Effect::setCurrentZoom(double cZ) +Effect::setSelectedNodePoints(std::vector selected_node_points) { - current_zoom = cZ; + selectedNodesPoints = selected_node_points; } +std::vector +Effect::getSelectedNodes() +{ + size_t counter = 0; + std::vector result; + for (size_t i = 0; i < pathvector_before_effect.size(); i++) { + for (size_t j = 0; j < pathvector_before_effect[i].size_closed(); j++) { + if ((pathvector_before_effect[i].size_closed() == j-1 && + isNodePointSelected( pathvector_before_effect[i][j].finalPoint())) || + isNodePointSelected( pathvector_before_effect[i][j].initialPoint())) + { + result.push_back(counter); + } + counter++; + } + } + return result; +} + + bool -Effect::isNodePointSelected(Geom::Point const &nodePoint) const +Effect::isNodePointSelected(Geom::Point const &node_point) const { if (selectedNodesPoints.size() > 0) { using Geom::X; @@ -421,7 +441,7 @@ Effect::isNodePointSelected(Geom::Point const &nodePoint) const i != selectedNodesPoints.end(); ++i) { Geom::Point p = *i; Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); - Geom::Point p2(nodePoint[X],nodePoint[Y]); + Geom::Point p2(node_point[X],node_point[Y]); p2 *= transformCoordinate; if (Geom::are_near(p, p2, 0.01)) { return true; diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 898e089b7..1f08a2bae 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -59,8 +59,9 @@ public: void doOnApply_impl(SPLPEItem const* lpeitem); void doBeforeEffect_impl(SPLPEItem const* lpeitem); void setCurrentZoom(double cZ); - void setSelectedNodePoints(std::vector sNP); - bool isNodePointSelected(Geom::Point const &nodePoint) const; + void setSelectedNodePoints(std::vector selected_node_points); + std::vector getSelectedNodes(); + bool isNodePointSelected(Geom::Point const &node_point) const; virtual void doOnApply (SPLPEItem const* lpeitem); virtual void doBeforeEffect (SPLPEItem const* lpeitem); diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 48e68d366..83baab1d1 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -22,67 +22,65 @@ namespace Inkscape { namespace LivePathEffect { -static const Util::EnumData FilletMethodData[FM_END] = { - { FM_AUTO, N_("Auto"), "auto" }, { FM_ARC, N_("Force arc"), "arc" }, +static const Util::EnumData Fillet_methodData[] = { + { FM_AUTO, N_("Auto"), "auto" }, + { FM_ARC, N_("Force arc"), "arc" }, { FM_BEZIER, N_("Force bezier"), "bezier" } }; -static const Util::EnumDataConverter FMConverter(FilletMethodData, - FM_END); +static const Util::EnumDataConverter FMConverter(Fillet_methodData, FM_END); LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellites_param(_("pair_array_param"), _("pair_array_param"), - "satellites_param", &wr, this), - method(_("Method:"), _("Methods to calculate the fillet or chamfer"), - "method", FMConverter, &wr, this, FM_AUTO), - radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, + _satellites_param("satellites_param", "satellites_param", + "_satellites_param", &wr, this), + _method(_("_method:"), _("_methods to calculate the fillet or chamfer"), + "_method", FMConverter, &wr, this, FM_AUTO), + _radius(_("_radius (unit or %):"), _("_radius, in unit or %"), "_radius", &wr, this, 0.0), - chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", + _chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "_chamfer_steps", &wr, this, 1), - flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), - "flexible", &wr, this, false), - mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "mirror_knots", &wr, + _flexible(_("_flexible _radius size (%)"), _("_flexible _radius size (%)"), + "_flexible", &wr, this, false), + _mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "_mirror_knots", &wr, this, true), - only_selected(_("Change only selected nodes"), - _("Change only selected nodes"), "only_selected", &wr, this, + _only_selected(_("Change only selected nodes"), + _("Change only selected nodes"), "_only_selected", &wr, this, false), - use_knot_distance(_("Use knots distance instead radius"), - _("Use knots distance instead radius"), - "use_knot_distance", &wr, this, false), - hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, + _use_knot_distance(_("Use knots distance instead _radius"), + _("Use knots distance instead _radius"), + "_use_knot_distance", &wr, this, false), + _hide_knots(_("Hide knots"), _("Hide knots"), "_hide_knots", &wr, this, false), - apply_no_radius(_("Apply changes if radius = 0"), _("Apply changes if radius = 0"), "apply_no_radius", &wr, this, true), - apply_with_radius(_("Apply changes if radius > 0"), _("Apply changes if radius > 0"), "apply_with_radius", &wr, this, true), - helper_size(_("Helper size with direction:"), - _("Helper size with direction"), "helper_size", &wr, this, 0), - pathvector_satellites(NULL), - degenerate_hide(false) + _apply_no_radius(_("Apply changes if _radius = 0"), _("Apply changes if _radius = 0"), "_apply_no_radius", &wr, this, true), + _apply_with_radius(_("Apply changes if _radius > 0"), _("Apply changes if _radius > 0"), "_apply_with_radius", &wr, this, true), + _helper_size(_("Helper path size with direction to node:"), + _("Helper path size with direction to node"), "_helper_size", &wr, this, 0), + _pathvector_satellites(NULL), + _degenerate_hide(false) { - registerParameter(&satellites_param); - registerParameter(&method); - registerParameter(&radius); - registerParameter(&chamfer_steps); - registerParameter(&helper_size); - registerParameter(&flexible); - registerParameter(&use_knot_distance); - registerParameter(&mirror_knots); - registerParameter(&apply_no_radius); - registerParameter(&apply_with_radius); - registerParameter(&only_selected); - registerParameter(&hide_knots); + registerParameter(&_satellites_param); + registerParameter(&_method); + registerParameter(&_radius); + registerParameter(&_chamfer_steps); + registerParameter(&_helper_size); + registerParameter(&_flexible); + registerParameter(&_use_knot_distance); + registerParameter(&_mirror_knots); + registerParameter(&_apply_no_radius); + registerParameter(&_apply_with_radius); + registerParameter(&_only_selected); + registerParameter(&_hide_knots); - radius.param_set_range(0.0, Geom::infinity()); - radius.param_set_increments(1, 1); - radius.param_set_digits(4); - radius.param_overwrite_widget(true); - chamfer_steps.param_set_range(1, 999); - chamfer_steps.param_set_increments(1, 1); - chamfer_steps.param_set_digits(0); - //chamfer_steps.param_overwrite_widget(true); - helper_size.param_set_range(0, 999); - helper_size.param_set_increments(5, 5); - helper_size.param_set_digits(0); - //helper_size.param_overwrite_widget(true); + _radius.param_set_range(0.0, Geom::infinity()); + _radius.param_set_increments(1, 1); + _radius.param_set_digits(4); + _radius.param_overwrite_widget(true); + _chamfer_steps.param_set_range(1, 999); + _chamfer_steps.param_set_increments(1, 1); + _chamfer_steps.param_set_digits(0); + _helper_size.param_set_range(0, 999); + _helper_size.param_set_increments(5, 5); + _helper_size.param_set_digits(0); } void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) @@ -103,24 +101,24 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) // continue //} Satellite satellite(FILLET); - satellite.setSteps(chamfer_steps); + satellite.setSteps(_chamfer_steps); subpath_satellites.push_back(satellite); } - //we add the last satellite on open path because pathvector_satellites is related to nodes, not curves + //we add the last satellite on open path because _pathvector_satellites is related to nodes, not curves //so maybe in the future we can need this last satellite in other effects - //dont remove for this effect because pathvector_satellites class has methods when the path is modiffied - //and we want one method for all uses + //dont remove for this effect because _pathvector_satellites class has _methods when the path is modiffied + //and we want one _method for all uses if (!path_it->closed()) { Satellite satellite(FILLET); - satellite.setSteps(chamfer_steps); + satellite.setSteps(_chamfer_steps); subpath_satellites.push_back(satellite); } satellites.push_back(subpath_satellites); } - pathvector_satellites = new PathVectorSatellites(); - pathvector_satellites->setPathVector(pathv); - pathvector_satellites->setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathvector_satellites); + _pathvector_satellites = new PathVectorSatellites(); + _pathvector_satellites->setPathVector(pathv); + _pathvector_satellites->setSatellites(satellites); + _satellites_param.setPathVectorSatellites(_pathvector_satellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem *item = const_cast(lpeItem); @@ -142,7 +140,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() if ((*it)->widget_is_visible) { Parameter *param = *it; Gtk::Widget *widg = param->param_newWidget(); - if (param->param_key == "radius") { + if (param->param_key == "_radius") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); widg_registered->signal_value_changed().connect( @@ -154,7 +152,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(6); } - } else if (param->param_key == "chamfer_steps") { + } else if (param->param_key == "_chamfer_steps") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); widg_registered->signal_value_changed().connect( @@ -166,12 +164,12 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(3); } - } else if (param->param_key == "helper_size") { + } else if (param->param_key == "_helper_size") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); widg_registered->signal_value_changed().connect( sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); - } else if (param->param_key == "only_selected") { + } else if (param->param_key == "_only_selected") { Gtk::manage(widg); } Glib::ustring *tip = param->param_getTooltip(); @@ -189,29 +187,25 @@ Gtk::Widget *LPEFilletChamfer::newWidget() } Gtk::HBox *fillet_container = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *fillet = - Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); + Gtk::Button *fillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Fillet")))); fillet->signal_clicked() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::fillet)); + .connect(sigc::bind(sigc::mem_fun(*this, &LPEFilletChamfer::updateSatelliteType),FILLET)); fillet_container->pack_start(*fillet, true, true, 2); - Gtk::Button *inverse_fillet = - Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); + Gtk::Button *inverse_fillet = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse fillet")))); inverse_fillet->signal_clicked() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseFillet)); + .connect(sigc::bind(sigc::mem_fun(*this, &LPEFilletChamfer::updateSatelliteType),INVERSE_FILLET)); fillet_container->pack_start(*inverse_fillet, true, true, 2); Gtk::HBox *chamfer_container = Gtk::manage(new Gtk::HBox(true, 0)); - Gtk::Button *chamfer = - Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); + Gtk::Button *chamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Chamfer")))); chamfer->signal_clicked() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamfer)); + .connect(sigc::bind(sigc::mem_fun(*this, &LPEFilletChamfer::updateSatelliteType),CHAMFER)); chamfer_container->pack_start(*chamfer, true, true, 2); - Gtk::Button *inverse_chamfer = - Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); + Gtk::Button *inverse_chamfer = Gtk::manage(new Gtk::Button(Glib::ustring(_("Inverse chamfer")))); inverse_chamfer->signal_clicked() - .connect(sigc::mem_fun(*this, &LPEFilletChamfer::inverseChamfer)); + .connect(sigc::bind(sigc::mem_fun(*this, &LPEFilletChamfer::updateSatelliteType),INVERSE_CHAMFER)); chamfer_container->pack_start(*inverse_chamfer, true, true, 2); vbox->pack_start(*fillet_container, true, true, 2); @@ -220,136 +214,30 @@ Gtk::Widget *LPEFilletChamfer::newWidget() return vbox; } -void LPEFilletChamfer::fillet() -{ - updateSatelliteType(FILLET); -} - -void LPEFilletChamfer::inverseFillet() -{ - updateSatelliteType(INVERSE_FILLET); -} - -void LPEFilletChamfer::chamfer() -{ - updateSatelliteType(CHAMFER); -} - -void LPEFilletChamfer::inverseChamfer() -{ - updateSatelliteType(INVERSE_CHAMFER); -} - void LPEFilletChamfer::refreshKnots() { - if (satellites_param.knoth) { - satellites_param.knoth->update_knots(); + if (_satellites_param._knoth) { + _satellites_param._knoth->update_knots(); } } void LPEFilletChamfer::updateAmount() { - double power = 0; - if (!flexible) { - power = radius; - } else { - power = radius / 100; - } - Satellites satellites = pathvector_satellites->getSatellites(); - Geom::PathVector pathv = pathvector_satellites->getPathVector(); - for (size_t i = 0; i < satellites.size(); ++i) { - for (size_t j = 0; j < satellites[i].size(); ++j) { - boost::optional previous_index = boost::none; - if(j == 0 && pathv[i].closed()){ - previous_index = pathv[i].size() - 1; - } else if(!pathv[i].closed() || j != 0) { - previous_index = j - 1; - } - if (!pathv[i].closed() && j == 0) { - satellites[i][j].amount = 0; - continue; - } - if (pathv[i].size() == j) { - continue; - } - if ((!apply_no_radius && satellites[i][j].amount == 0) || - (!apply_with_radius && satellites[i][j].amount != 0)) - { - continue; - } - - Geom::Point satellite_point = pathv[i].pointAt(j); - if (isNodePointSelected(satellite_point) || !only_selected) { - if (!use_knot_distance && !flexible) { - if(previous_index) { - satellites[i][j].amount = satellites[i][j].radToLen(power, pathv[i][*previous_index], pathv[i][j]); - } else { - satellites[i][j].amount = 0.0; - } - } else { - satellites[i][j].amount = power; - } - } - } - } - pathvector_satellites->setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathvector_satellites); + _pathvector_satellites->updateAmount(_radius, _apply_no_radius, _apply_with_radius, _only_selected, + _use_knot_distance, _flexible); + _satellites_param.setPathVectorSatellites(_pathvector_satellites); } void LPEFilletChamfer::updateChamferSteps() { - Satellites satellites = pathvector_satellites->getSatellites(); - Geom::PathVector pathv = pathvector_satellites->getPathVector(); - for (size_t i = 0; i < satellites.size(); ++i) { - for (size_t j = 0; j < satellites[i].size(); ++j) { - if ((!apply_no_radius && satellites[i][j].amount == 0) || - (!apply_with_radius && satellites[i][j].amount != 0)) - { - continue; - } - if (only_selected) { - Geom::Point satellite_point = pathv[i].pointAt(j); - if (isNodePointSelected(satellite_point)) { - satellites[i][j].steps = chamfer_steps; - } - } else { - satellites[i][j].steps = chamfer_steps; - } - } - } - pathvector_satellites->setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathvector_satellites); + _pathvector_satellites->updateSteps(_chamfer_steps, _apply_no_radius, _apply_with_radius, _only_selected); + _satellites_param.setPathVectorSatellites(_pathvector_satellites); } void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - Satellites satellites = pathvector_satellites->getSatellites(); - Geom::PathVector pathv = pathvector_satellites->getPathVector(); - for (size_t i = 0; i < satellites.size(); ++i) { - for (size_t j = 0; j < satellites[i].size(); ++j) { - if ((!apply_no_radius && satellites[i][j].amount == 0) || - (!apply_with_radius && satellites[i][j].amount != 0)) - { - continue; - } - if (pathv[i].size() == j) { - if (!only_selected) { - satellites[i][j].satellite_type = satellitetype; - } - continue; - } - if (only_selected) { - Geom::Point satellite_point = pathv[i].pointAt(j); - if (isNodePointSelected(satellite_point)) { - satellites[i][j].satellite_type = satellitetype; - } - } else { - satellites[i][j].satellite_type = satellitetype; - } - } - } - pathvector_satellites->setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathvector_satellites); + _pathvector_satellites->updateSatelliteType(satellitetype, _apply_no_radius, _apply_with_radius, _only_selected); + _satellites_param.setPathVectorSatellites(_pathvector_satellites); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -363,45 +251,46 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } //fillet chamfer specific calls - satellites_param.setUseDistance(use_knot_distance); + _satellites_param.setUseDistance(_use_knot_distance); //mandatory call - satellites_param.setEffectType(effectType()); + _satellites_param.setEffectType(effectType()); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 - if (pathvector_satellites) { + if (_pathvector_satellites) { size_t number_nodes = pathv.nodes().size(); - size_t satellites_counter = pathvector_satellites->getTotalSatellites(); + size_t satellites_counter = _pathvector_satellites->getTotalSatellites(); if (number_nodes != satellites_counter) { Satellite satellite(FILLET); - satellite.setIsTime(flexible); - satellite.setHasMirror(mirror_knots); - satellite.setHidden(hide_knots); - pathvector_satellites->recalculateForNewPathVector(pathv, satellite); - satellites_param.setPathVectorSatellites(pathvector_satellites); + satellite.setIsTime(_flexible); + satellite.setHasMirror(_mirror_knots); + satellite.setHidden(_hide_knots); + _pathvector_satellites->recalculateForNewPathVector(pathv, satellite); + _pathvector_satellites->setSelected(getSelectedNodes()); + _satellites_param.setPathVectorSatellites(_pathvector_satellites); refreshKnots(); return; } } - Satellites satellites = satellites_param.data(); + Satellites satellites = _satellites_param.data(); if(satellites.empty()) { doOnApply(lpeItem); - satellites = satellites_param.data(); + satellites = _satellites_param.data(); } - if (degenerate_hide) { - satellites_param.setGlobalKnotHide(true); + if (_degenerate_hide) { + _satellites_param.setGlobalKnotHide(true); } else { - satellites_param.setGlobalKnotHide(false); + _satellites_param.setGlobalKnotHide(false); } - if (hide_knots) { - satellites_param.setHelperSize(0); + if (_hide_knots) { + _satellites_param.setHelperSize(0); } else { - satellites_param.setHelperSize(helper_size); + _satellites_param.setHelperSize(_helper_size); } for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { - if (satellites[i][j].is_time != flexible) { - satellites[i][j].is_time = flexible; + if (satellites[i][j].is_time != _flexible) { + satellites[i][j].is_time = _flexible; double amount = satellites[i][j].amount; if (pathv[i].size() == j){ continue; @@ -415,16 +304,17 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].amount = size; } } - if (satellites[i][j].has_mirror != mirror_knots) { - satellites[i][j].has_mirror = mirror_knots; + if (satellites[i][j].has_mirror != _mirror_knots) { + satellites[i][j].has_mirror = _mirror_knots; } - satellites[i][j].hidden = hide_knots; + satellites[i][j].hidden = _hide_knots; } } - pathvector_satellites = new PathVectorSatellites(); - pathvector_satellites->setPathVector(pathv); - pathvector_satellites->setSatellites(satellites); - satellites_param.setPathVectorSatellites(pathvector_satellites); + _pathvector_satellites = new PathVectorSatellites(); + _pathvector_satellites->setPathVector(pathv); + _pathvector_satellites->setSatellites(satellites); + _pathvector_satellites->setSelected(getSelectedNodes()); + _satellites_param.setPathVectorSatellites(_pathvector_satellites); refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); @@ -444,7 +334,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::PathVector path_out; size_t path = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); - degenerate_hide = false; + _degenerate_hide = false; Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { if (path_it->empty()) { @@ -460,7 +350,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } double time0 = 0; size_t curve = 0; - Satellites satellites = pathvector_satellites->getSatellites(); + Satellites satellites = _pathvector_satellites->getSatellites(); for (Geom::Path::const_iterator curve_it1 = path_it->begin(); curve_it1 != path_it->end(); ++curve_it1) { size_t next_index = curve + 1; if (curve == pathv[path].size() - 1 && pathv[path].closed()) { @@ -476,7 +366,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } Satellite satellite = satellites[path][next_index]; if (Geom::are_near((*curve_it1).initialPoint(),(*curve_it1).finalPoint())) { - degenerate_hide = true; + _degenerate_hide = true; g_warning("Knots hidded if consecutive nodes has the same position."); return path_in; } @@ -563,10 +453,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); Geom::Line const angled_line(start_arc_point, end_arc_point); double arc_angle = Geom::angle_between(x_line, angled_line); - double radius = Geom::distance(start_arc_point, + double _radius = Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)) / sin(angle / 2.0); - Geom::Coord rx = radius; + Geom::Coord rx = _radius; Geom::Coord ry = rx; if (times[1] != 1) { if (times[1] != times[0] || (times[1] == 1 && times[0] == 1)) { @@ -583,8 +473,8 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && method != FM_BEZIER) || - method == FM_ARC) { + is_straight_curve(curve_it2) && _method != FM_BEZIER) || + _method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); @@ -592,9 +482,9 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) path_chamfer.appendNew(handle_1, handle_2, end_arc_point); } - double chamfer_stepsTime = 1.0 / steps; + double _chamfer_stepsTime = 1.0 / steps; for (size_t i = 1; i < steps; i++) { - Geom::Point chamfer_step = path_chamfer.pointAt(chamfer_stepsTime * i); + Geom::Point chamfer_step = path_chamfer.pointAt(_chamfer_stepsTime * i); tmp_path.appendNew(chamfer_step); } tmp_path.appendNew(end_arc_point); @@ -602,25 +492,25 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && method != FM_BEZIER) || - method == FM_ARC) { + is_straight_curve(curve_it2) && _method != FM_BEZIER) || + _method == FM_ARC) { path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { path_chamfer.appendNew( inverse_handle_1, inverse_handle_2, end_arc_point); } - double chamfer_stepsTime = 1.0 / steps; + double _chamfer_stepsTime = 1.0 / steps; for (size_t i = 1; i < steps; i++) { Geom::Point chamfer_step = - path_chamfer.pointAt(chamfer_stepsTime * i); + path_chamfer.pointAt(_chamfer_stepsTime * i); tmp_path.appendNew(chamfer_step); } tmp_path.appendNew(end_arc_point); } else if (type == INVERSE_FILLET) { if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && method != FM_BEZIER) || - method == FM_ARC) { + is_straight_curve(curve_it2) && _method != FM_BEZIER) || + _method == FM_ARC) { tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { @@ -629,8 +519,8 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } } else if (type == FILLET) { if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && method != FM_BEZIER) || - method == FM_ARC) { + is_straight_curve(curve_it2) && _method != FM_BEZIER) || + _method == FM_ARC) { ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 420403b70..bd0b74b51 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -20,7 +20,7 @@ namespace Inkscape { namespace LivePathEffect { -enum FilletMethod { +enum Fillet_method { FM_AUTO, FM_ARC, FM_BEZIER, @@ -40,28 +40,24 @@ public: void updateChamferSteps(); void updateAmount(); void refreshKnots(); - void chamfer(); - void inverseChamfer(); - void fillet(); - void inverseFillet(); - SatellitesArrayParam satellites_param; + SatellitesArrayParam _satellites_param; private: - EnumParam method; - ScalarParam radius; - ScalarParam chamfer_steps; - BoolParam flexible; - BoolParam mirror_knots; - BoolParam only_selected; - BoolParam use_knot_distance; - BoolParam hide_knots; - BoolParam apply_no_radius; - BoolParam apply_with_radius; - ScalarParam helper_size; + EnumParam _method; + ScalarParam _radius; + ScalarParam _chamfer_steps; + BoolParam _flexible; + BoolParam _mirror_knots; + BoolParam _only_selected; + BoolParam _use_knot_distance; + BoolParam _hide_knots; + BoolParam _apply_no_radius; + BoolParam _apply_with_radius; + ScalarParam _helper_size; - bool degenerate_hide; - PathVectorSatellites *pathvector_satellites; + bool _degenerate_hide; + PathVectorSatellites *_pathvector_satellites; Geom::PathVector _hp; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 1cd59b7fa..3c4ce0708 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -434,7 +434,7 @@ LPETransform2Pts::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector< } if(!lock_angle && lock_lenght) { char const * svgd; - svgd = "m 7.07,7.07 c -3.9,3.91 -10.24,3.91 -14.14,0 -3.91,-3.9 -3.91,-10.24 0,-14.14 3.9,-3.91 10.24,-3.91 14.14,0 l -2.83,-4.24 -0.7,2.12"; + svgd = "M 0,9.94 C -2.56,9.91 -5.17,8.98 -7.07,7.07 c -3.91,-3.9 -3.91,-10.24 0,-14.14 1.97,-1.97 4.51,-3.02 7.07,-3.04 2.56,0.02 5.1,1.07 7.07,3.04 3.91,3.9 3.91,10.24 0,14.14 C 5.17,8.98 2.56,9.91 0,9.94 Z"; PathVector pathv_turn = sp_svg_read_pathv(svgd); pathv_turn *= Geom::Rotate(previous_angle); pathv_turn *= Affine(r,0,0,r,0,0) * Translate(Geom::Point(end)); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 4e3037904..28867def2 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -58,18 +58,19 @@ ArrayParam >::readsvg(const gchar * str) gchar ** strarray = g_strsplit(str, "@", 0); gchar ** iter = strarray; while (*iter != NULL) { - gchar ** strsubarray = g_strsplit(*iter, ",", 7); - if(*strsubarray[6]){ + gchar ** strsubarray = g_strsplit(*iter, ",", 8); + if(*strsubarray[7]){//steps always > 0 Satellite *satellite = new Satellite(); satellite->setSatelliteType(g_strstrip(strsubarray[0])); satellite->is_time = strncmp(strsubarray[1],"1",1) == 0; - satellite->has_mirror = strncmp(strsubarray[2],"1",1) == 0; - satellite->hidden = strncmp(strsubarray[3],"1",1) == 0; + satellite->selected = strncmp(strsubarray[2],"1",1) == 0; + satellite->has_mirror = strncmp(strsubarray[3],"1",1) == 0; + satellite->hidden = strncmp(strsubarray[4],"1",1) == 0; double amount,angle; float stepsTmp; - sp_svg_number_read_d(strsubarray[4], &amount); - sp_svg_number_read_d(strsubarray[5], &angle); - sp_svg_number_read_f(g_strstrip(strsubarray[6]), &stepsTmp); + sp_svg_number_read_d(strsubarray[5], &amount); + sp_svg_number_read_d(strsubarray[6], &angle); + sp_svg_number_read_f(g_strstrip(strsubarray[7]), &stepsTmp); unsigned int steps = (unsigned int)stepsTmp; satellite->amount = amount; satellite->angle = angle; diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 9802abc2e..9204ede1f 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -120,6 +120,8 @@ protected: str << ","; str << vector_data[i].is_time; str << ","; + str << vector_data[i].selected; + str << ","; str << vector_data[i].has_mirror; str << ","; str << vector_data[i].hidden; diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 18e1bd4de..2f5cea7b5 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -26,7 +26,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayParam >(label, tip, key, wr, effect, 0), knoth(NULL) + : ArrayParam >(label, tip, key, wr, effect, 0), _knoth(NULL) { _knot_shape = SP_KNOT_SHAPE_DIAMOND; _knot_mode = SP_KNOT_MODE_XOR; @@ -180,6 +180,9 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) } } } + if(!_knot_reset_helper.empty()){ + _hp.insert(_hp.end(), _knot_reset_helper.begin(), _knot_reset_helper.end() ); + } if (mirror) { updateCanvasIndicators(false); } @@ -230,24 +233,21 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, using namespace Geom; //If is for filletChamfer effect... if (_effectType == FILLET_CHAMFER) { -// if(!pathv[i].closed() && (j == 0 || j == _vector[i].size() -1)) { -// continue; -// } const gchar *tip; if (type == CHAMFER) { - tip = _("Chamfer: Ctrl+Click toggle type, " + tip = _("Chamfer: Ctrl+Click toggles type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } else if (type == INVERSE_CHAMFER) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + tip = _("Inverse Chamfer: Ctrl+Click toggles type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } else if (type == INVERSE_FILLET) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " + tip = _("Inverse Fillet: Ctrl+Click toggles type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } else { - tip = _("Fillet: Ctrl+Click toggle type, " + tip = _("Fillet: Ctrl+Click toggles type, " "Shift+Click open dialog, " "Ctrl+Alt+Click reset"); } @@ -267,7 +267,7 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { - knoth = knotholder; + _knoth = knotholder; addKnotHolderEntities(knotholder, desktop, item, true); } @@ -316,6 +316,14 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point normal = pathv[path_index][curve_index].pointAt(normal_time); double distance_mirror = Geom::distance(mirror,s); double distance_normal = Geom::distance(normal,s); + //this avoid toggle when fillet are near node +// if (is_mirror && Geom::are_near(mirror, pathv[path_index][curve_index].initialPoint())) { +// distance_mirror = 0.0; +// distance_normal = 1.0; +// } else if (!is_mirror && Geom::are_near(normal, pathv[path_index][curve_index].initialPoint())){ +// distance_mirror = 1.0; +// distance_normal = 0.0; +// } if (distance_mirror <= distance_normal) { double time_start = 0; Satellites satellites = _pparam->_last_pathvector_satellites->getSatellites(); @@ -332,6 +340,15 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, } else { satellite.setPosition(s, pathv[path_index][curve_index]); } + _pparam->_knot_reset_helper.clear(); + if (satellite.amount == 0){ + char const *svgd; + svgd = "M -5.39,8.78 -9.13,5.29 -10.38,10.28 Z M -7.22,7.07 -3.43,3.37 m -1.95,-12.16 -3.74,3.5 -1.26,-5 z " + "m -1.83,1.71 3.78,3.7 M 5.24,8.78 8.98,5.29 10.24,10.28 Z " + "M 7.07,7.07 3.29,3.37 M 5.24,-8.78 l 3.74,3.5 1.26,-5 z M 7.07,-7.07 3.29,-3.37"; + _pparam->_knot_reset_helper = sp_svg_read_pathv(svgd); + _pparam->_knot_reset_helper *= Geom::Affine(_pparam->_helper_size * 0.1,0,0,_pparam->_helper_size * 0.1,0,0) * Geom::Translate(Geom::Point(normal)); + } _pparam->_vector[path_index][curve_index] = satellite; SPLPEItem *splpeitem = dynamic_cast(item); if (splpeitem) { @@ -446,21 +463,21 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); const gchar *tip; if (type == CHAMFER) { - tip = _("Chamfer: Ctrl+Click toggle type, " + tip = _("Chamfer: Ctrl+Click toggles type, " "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); + "Ctrl+Alt+Click resets"); } else if (type == INVERSE_CHAMFER) { - tip = _("Inverse Chamfer: Ctrl+Click toggle type, " + tip = _("Inverse Chamfer: Ctrl+Click toggles type, " "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); + "Ctrl+Alt+Click resets"); } else if (type == INVERSE_FILLET) { - tip = _("Inverse Fillet: Ctrl+Click toggle type, " + tip = _("Inverse Fillet: Ctrl+Click toggles type, " "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); + "Ctrl+Alt+Click resets"); } else { - tip = _("Fillet: Ctrl+Click toggle type, " + tip = _("Fillet: Ctrl+Click toggles type, " "Shift+Click open dialog, " - "Ctrl+Alt+Click reset"); + "Ctrl+Alt+Click resets"); } this->knot->tip = g_strdup(tip); this->knot->show(); diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index 30b1db6c1..64bc934c8 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -64,7 +64,7 @@ public: friend class LPEFilletChamfer; protected: - KnotHolder *knoth; + KnotHolder *_knoth; private: SatellitesArrayParam(const SatellitesArrayParam &); @@ -74,6 +74,7 @@ private: SPKnotModeType _knot_mode; guint32 _knot_color; Geom::PathVector _hp; + Geom::PathVector _knot_reset_helper; int _helper_size; bool _use_distance; bool _global_knot_hide; @@ -87,7 +88,7 @@ public: FilletChamferKnotHolderEntity(SatellitesArrayParam *p, size_t index); virtual ~FilletChamferKnotHolderEntity() { - _pparam->knoth = NULL; + _pparam->_knoth = NULL; } virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 23aaf6bb1..60d4c807f 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(); -- cgit v1.2.3 From 2c544b51a588c8874b5b5f9a5e1e33d591972b15 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 14 Jun 2016 23:44:32 +0200 Subject: Add snap to origin in double direction knots (bzr r13645.1.157) --- src/live_effects/lpe-fillet-chamfer.cpp | 1 + src/live_effects/lpe-fillet-chamfer.h | 4 ++-- src/live_effects/parameter/satellitesarray.cpp | 20 ++++++++++---------- src/live_effects/parameter/satellitesarray.h | 2 ++ 4 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 83baab1d1..ef5f8f0a5 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -252,6 +252,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } //fillet chamfer specific calls _satellites_param.setUseDistance(_use_knot_distance); + _satellites_param.setCurrentZoom(current_zoom); //mandatory call _satellites_param.setEffectType(effectType()); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index bd0b74b51..8a3701f7d 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -31,10 +31,10 @@ class LPEFilletChamfer : public Effect { public: LPEFilletChamfer(LivePathEffectObject *lpeobject); virtual void doBeforeEffect(SPLPEItem const *lpeItem); - virtual Geom::PathVector - doEffect_path(Geom::PathVector const &path_in); + virtual Geom::PathVector doEffect_path(Geom::PathVector const &path_in); virtual void doOnApply(SPLPEItem const *lpeItem); virtual Gtk::Widget *newWidget(); + Geom::Ray getRay(Geom::Point start, Geom::Point end, Geom::Curve *curve, bool reverse); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(SatelliteType satellitetype); void updateChamferSteps(); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 2f5cea7b5..c0141ddfa 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -34,6 +34,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, _helper_size = 0; _use_distance = false; _global_knot_hide = false; + _current_zoom = 0; _effectType = FILLET_CHAMFER; _last_pathvector_satellites = NULL; } @@ -58,6 +59,11 @@ void SatellitesArrayParam::setUseDistance(bool use_knot_distance) _use_distance = use_knot_distance; } +void SatellitesArrayParam::setCurrentZoom(double current_zoom) +{ + _current_zoom = current_zoom; +} + void SatellitesArrayParam::setGlobalKnotHide(bool global_knot_hide) { _global_knot_hide = global_knot_hide; @@ -316,15 +322,9 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point normal = pathv[path_index][curve_index].pointAt(normal_time); double distance_mirror = Geom::distance(mirror,s); double distance_normal = Geom::distance(normal,s); - //this avoid toggle when fillet are near node -// if (is_mirror && Geom::are_near(mirror, pathv[path_index][curve_index].initialPoint())) { -// distance_mirror = 0.0; -// distance_normal = 1.0; -// } else if (!is_mirror && Geom::are_near(normal, pathv[path_index][curve_index].initialPoint())){ -// distance_mirror = 1.0; -// distance_normal = 0.0; -// } - if (distance_mirror <= distance_normal) { + if (Geom::are_near(s, pathv[path_index][curve_index].initialPoint(), 1.5 / _pparam->_current_zoom)) { + satellite.amount = 0; + } else if (distance_mirror < distance_normal) { double time_start = 0; Satellites satellites = _pparam->_last_pathvector_satellites->getSatellites(); time_start = satellites[path_index][previous_index].time(curve_in); @@ -347,7 +347,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, "m -1.83,1.71 3.78,3.7 M 5.24,8.78 8.98,5.29 10.24,10.28 Z " "M 7.07,7.07 3.29,3.37 M 5.24,-8.78 l 3.74,3.5 1.26,-5 z M 7.07,-7.07 3.29,-3.37"; _pparam->_knot_reset_helper = sp_svg_read_pathv(svgd); - _pparam->_knot_reset_helper *= Geom::Affine(_pparam->_helper_size * 0.1,0,0,_pparam->_helper_size * 0.1,0,0) * Geom::Translate(Geom::Point(normal)); + _pparam->_knot_reset_helper *= Geom::Affine(_pparam->_helper_size * 0.1,0,0,_pparam->_helper_size * 0.1,0,0) * Geom::Translate(pathv[path_index][curve_index].initialPoint()); } _pparam->_vector[path_index][curve_index] = satellite; SPLPEItem *splpeitem = dynamic_cast(item); diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index 64bc934c8..5b2d8a799 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -55,6 +55,7 @@ public: } void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void setUseDistance(bool use_knot_distance); + void setCurrentZoom(double current_zoom); void setGlobalKnotHide(bool global_knot_hide); void setEffectType(EffectType et); void setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites); @@ -78,6 +79,7 @@ private: int _helper_size; bool _use_distance; bool _global_knot_hide; + double _current_zoom; EffectType _effectType; PathVectorSatellites *_last_pathvector_satellites; -- cgit v1.2.3 From c631289820725ebd027571ec34ae2a1540cc3713 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 18 Jun 2016 10:33:51 +0200 Subject: attemp to simplify doeffect code on fillet chamfer (bzr r13645.1.159) --- src/live_effects/lpe-fillet-chamfer.cpp | 109 +++++++++++++++----------------- src/live_effects/lpe-fillet-chamfer.h | 1 + 2 files changed, 51 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index ef5f8f0a5..f2ed8d4d8 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -328,6 +328,17 @@ LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector< hp_vec.push_back(_hp); } +void +LPEFilletChamfer::addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point) +{ + double path_subdivision = 1.0 / steps; + for (size_t i = 1; i < steps; i++) { + Geom::Point chamfer_step = path_chamfer.pointAt(path_subdivision * i); + tmp_path.appendNew(chamfer_step); + } + tmp_path.appendNew(end_arc_point); +} + Geom::PathVector LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) { @@ -470,65 +481,45 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (steps < 1) { steps = 1; } - if (type == CHAMFER) { - Geom::Path path_chamfer; - path_chamfer.start(tmp_path.finalPoint()); - if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && _method != FM_BEZIER) || - _method == FM_ARC) { - ccw_toggle = ccw_toggle ? 0 : 1; - path_chamfer.appendNew(rx, ry, arc_angle, 0, - ccw_toggle, end_arc_point); - } else { - path_chamfer.appendNew(handle_1, handle_2, - end_arc_point); - } - double _chamfer_stepsTime = 1.0 / steps; - for (size_t i = 1; i < steps; i++) { - Geom::Point chamfer_step = path_chamfer.pointAt(_chamfer_stepsTime * i); - tmp_path.appendNew(chamfer_step); - } - tmp_path.appendNew(end_arc_point); - } else if (type == INVERSE_CHAMFER) { - Geom::Path path_chamfer; - path_chamfer.start(tmp_path.finalPoint()); - if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && _method != FM_BEZIER) || - _method == FM_ARC) { - path_chamfer.appendNew(rx, ry, arc_angle, 0, - ccw_toggle, end_arc_point); - } else { - path_chamfer.appendNew( - inverse_handle_1, inverse_handle_2, end_arc_point); - } - double _chamfer_stepsTime = 1.0 / steps; - for (size_t i = 1; i < steps; i++) { - Geom::Point chamfer_step = - path_chamfer.pointAt(_chamfer_stepsTime * i); - tmp_path.appendNew(chamfer_step); - } - tmp_path.appendNew(end_arc_point); - } else if (type == INVERSE_FILLET) { - if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && _method != FM_BEZIER) || - _method == FM_ARC) { - tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, - end_arc_point); - } else { - tmp_path.appendNew(inverse_handle_1, - inverse_handle_2, end_arc_point); - } - } else if (type == FILLET) { - if ((is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && _method != FM_BEZIER) || - _method == FM_ARC) { - ccw_toggle = ccw_toggle ? 0 : 1; - tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, - end_arc_point); - } else { - tmp_path.appendNew(handle_1, handle_2, - end_arc_point); - } + bool eliptical = (is_straight_curve(*curve_it1) && + is_straight_curve(curve_it2) && _method != FM_BEZIER) || + _method == FM_ARC; + switch (type) { + case CHAMFER: + Geom::Path path_chamfer; + path_chamfer.start(tmp_path.finalPoint()); + if (eliptical) { + ccw_toggle = ccw_toggle ? 0 : 1; + path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); + } else { + path_chamfer.appendNew(handle_1, handle_2, end_arc_point); + } + addChamferSteps(tmp_path, path_chamfer, end_arc_point); + break; + case INVERSE_CHAMFER: + Geom::Path path_chamfer; + path_chamfer.start(tmp_path.finalPoint()); + if (eliptical) { + path_chamfer.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); + } else { + path_chamfer.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); + } + addChamferSteps(tmp_path, path_chamfer, end_arc_point); + break; + case INVERSE_FILLET: + if (eliptical) { + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); + } else { + tmp_path.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); + } + break; + default: //fillet + if (eliptical) { + ccw_toggle = ccw_toggle ? 0 : 1; + tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); + } else { + tmp_path.appendNew(handle_1, handle_2, end_arc_point); + } } } else { if (!knot_curve_1->isDegenerate()) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 8a3701f7d..35e9028f3 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -35,6 +35,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual Gtk::Widget *newWidget(); Geom::Ray getRay(Geom::Point start, Geom::Point end, Geom::Curve *curve, bool reverse); + void addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(SatelliteType satellitetype); void updateChamferSteps(); -- cgit v1.2.3 From c5f642fbd66ccb150d361d2861d0b1baa744dcba Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 18 Jun 2016 15:07:51 +0200 Subject: Pre fixing selected points (bzr r13645.1.161) --- src/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 +- src/live_effects/parameter/satellitesarray.cpp | 45 ++++++++++++--------- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 7 ++-- src/ui/tools/node-tool.cpp | 6 +-- 8 files changed, 80 insertions(+), 58 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index c56887f53..e80d812d7 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 f60d628f6..515aa26fc 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -406,9 +406,9 @@ Effect::setCurrentZoom(double cZ) } void -Effect::setSelectedNodePoints(std::vector selected_node_points) +Effect::setSelectedNodePoints(std::vector selected_nodes_pos) { - selectedNodesPoints = selected_node_points; + _selected_nodes_pos = selected_nodes_pos; } std::vector @@ -418,7 +418,8 @@ Effect::getSelectedNodes() std::vector result; for (size_t i = 0; i < pathvector_before_effect.size(); i++) { for (size_t j = 0; j < pathvector_before_effect[i].size_closed(); j++) { - if ((pathvector_before_effect[i].size_closed() == j-1 && + if ((!pathvector_before_effect[i].closed() && + pathvector_before_effect[i].size_closed() == j-1 && isNodePointSelected( pathvector_before_effect[i][j].finalPoint())) || isNodePointSelected( pathvector_before_effect[i][j].initialPoint())) { @@ -434,11 +435,11 @@ Effect::getSelectedNodes() bool Effect::isNodePointSelected(Geom::Point const &node_point) const { - if (selectedNodesPoints.size() > 0) { + if (_selected_nodes_pos.size() > 0) { using Geom::X; using Geom::Y; - for (std::vector::const_iterator i = selectedNodesPoints.begin(); - i != selectedNodesPoints.end(); ++i) { + for (std::vector::const_iterator i = _selected_nodes_pos.begin(); + i != _selected_nodes_pos.end(); ++i) { Geom::Point p = *i; Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); Geom::Point p2(node_point[X],node_point[Y]); diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 1f08a2bae..3b02b14d4 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -59,7 +59,7 @@ public: void doOnApply_impl(SPLPEItem const* lpeitem); void doBeforeEffect_impl(SPLPEItem const* lpeitem); void setCurrentZoom(double cZ); - void setSelectedNodePoints(std::vector selected_node_points); + void setSelectedNodePoints(std::vector selected_nodes_pos); std::vector getSelectedNodes(); bool isNodePointSelected(Geom::Point const &node_point) const; virtual void doOnApply (SPLPEItem const* lpeitem); @@ -163,7 +163,7 @@ protected: SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. double current_zoom; - std::vector selectedNodesPoints; + std::vector _selected_nodes_pos; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; private: diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f2ed8d4d8..7a663614b 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -260,8 +260,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //TODO: Update the satellite data in paths modified, Goal 0.93 if (_pathvector_satellites) { size_t number_nodes = pathv.nodes().size(); - size_t satellites_counter = _pathvector_satellites->getTotalSatellites(); - if (number_nodes != satellites_counter) { + size_t previous_number_nodes = _pathvector_satellites->getPathVector().nodes().size(); + if (number_nodes != previous_number_nodes) { + std::cout << "sfsfaasfasfasfasffasdf\n"; Satellite satellite(FILLET); satellite.setIsTime(_flexible); satellite.setHasMirror(_mirror_knots); @@ -329,7 +330,7 @@ LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector< } void -LPEFilletChamfer::addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point) +LPEFilletChamfer::addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point, size_t steps) { double path_subdivision = 1.0 / steps; for (size_t i = 1; i < steps; i++) { @@ -462,14 +463,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (times[1] == times[0]) { start_arc_point = curve_it1->pointAt(times[0]); } - Geom::Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); - Geom::Line const angled_line(start_arc_point, end_arc_point); - double arc_angle = Geom::angle_between(x_line, angled_line); - double _radius = Geom::distance(start_arc_point, - middle_point(start_arc_point, end_arc_point)) / - sin(angle / 2.0); - Geom::Coord rx = _radius; - Geom::Coord ry = rx; if (times[1] != 1) { if (times[1] != times[0] || (times[1] == 1 && times[0] == 1)) { if (!knot_curve_1->isDegenerate()) { @@ -478,14 +471,20 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } SatelliteType type = satellite.satellite_type; size_t steps = satellite.steps; - if (steps < 1) { - steps = 1; - } + if (!steps) steps = 1; + Geom::Line const x_line(Geom::Point(0, 0), Geom::Point(1, 0)); + Geom::Line const angled_line(start_arc_point, end_arc_point); + double arc_angle = Geom::angle_between(x_line, angled_line); + double radius = Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)) / + sin(angle / 2.0); + Geom::Coord rx = radius; + Geom::Coord ry = rx; bool eliptical = (is_straight_curve(*curve_it1) && is_straight_curve(curve_it2) && _method != FM_BEZIER) || _method == FM_ARC; switch (type) { - case CHAMFER: + case CHAMFER: + { Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if (eliptical) { @@ -494,9 +493,11 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } else { path_chamfer.appendNew(handle_1, handle_2, end_arc_point); } - addChamferSteps(tmp_path, path_chamfer, end_arc_point); - break; - case INVERSE_CHAMFER: + addChamferSteps(tmp_path, path_chamfer, end_arc_point, steps); + } + break; + case INVERSE_CHAMFER: + { Geom::Path path_chamfer; path_chamfer.start(tmp_path.finalPoint()); if (eliptical) { @@ -504,22 +505,28 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } else { path_chamfer.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); } - addChamferSteps(tmp_path, path_chamfer, end_arc_point); - break; - case INVERSE_FILLET: + addChamferSteps(tmp_path, path_chamfer, end_arc_point, steps); + } + break; + case INVERSE_FILLET: + { if (eliptical) { tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { tmp_path.appendNew(inverse_handle_1, inverse_handle_2, end_arc_point); } - break; - default: //fillet + } + break; + default: //fillet + { if (eliptical) { ccw_toggle = ccw_toggle ? 0 : 1; tmp_path.appendNew(rx, ry, arc_angle, 0, ccw_toggle, end_arc_point); } else { tmp_path.appendNew(handle_1, handle_2, end_arc_point); } + } + break; } } else { if (!knot_curve_1->isDegenerate()) { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 35e9028f3..134886950 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -35,7 +35,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual Gtk::Widget *newWidget(); Geom::Ray getRay(Geom::Point start, Geom::Point end, Geom::Curve *curve, bool reverse); - void addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point); + void addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point, size_t steps); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(SatelliteType satellitetype); void updateChamferSteps(); @@ -56,7 +56,6 @@ private: BoolParam _apply_no_radius; BoolParam _apply_with_radius; ScalarParam _helper_size; - bool _degenerate_hide; PathVectorSatellites *_pathvector_satellites; Geom::PathVector _hp; diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index c0141ddfa..71c69c6c5 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -112,10 +112,13 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) bool overflow = false; double size_out = _vector[i][j].arcDistance(*curve_in); double lenght_out = curve_in->length(); - size_t previous_index = j - 1; //Always are previous index because we skip first satellite on open paths + gint previous_index = j - 1; //Always are previous index because we skip first satellite on open paths if(j == 0 && pathv[i].closed()){ previous_index = pathv[i].size() - 1; } + if( previous_index < 0 ) { + return; + } double lenght_in = pathv.curveAt(previous_index).length(); if (mirror) { curve_in = const_cast(&pathv.curveAt(previous_index)); @@ -311,10 +314,13 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, { return; } - size_t previous_index = curve_index - 1; + gint previous_index = curve_index - 1; if(curve_index == 0 && pathv[path_index].closed()){ previous_index = pathv[path_index].size() - 1; } + if( previous_index < 0 ) { + return; + } Geom::Curve const &curve_in = pathv[path_index][previous_index]; double mirror_time = Geom::nearest_time(s, curve_in); Geom::Point mirror = curve_in.pointAt(mirror_time); @@ -386,10 +392,13 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const this->knot->show(); if (is_mirror) { tmp_point = satellite.getPosition(pathv[path_index][curve_index]); - size_t previous_index = curve_index - 1; + gint previous_index = curve_index - 1; if(curve_index == 0 && pathv[path_index].closed()){ previous_index = pathv[path_index].size() - 1; } + if( previous_index < 0 ) { + return Geom::Point(Geom::infinity(), Geom::infinity()); + } Geom::Curve const &curve_in = pathv[path_index][previous_index]; double s = satellite.arcDistance(pathv[path_index][curve_index]); double t = satellite.time(s, true, curve_in); @@ -484,27 +493,24 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } } else if (state & GDK_SHIFT_MASK) { double amount = _pparam->_vector[path_index][curve_index].amount; - size_t previous_index = curve_index - 1; + gint previous_index = curve_index - 1; if(curve_index == 0 && pathv[path_index].closed()){ previous_index = pathv[path_index].size() - 1; } + if( previous_index < 0 ) { + return; + } if (!_pparam->_use_distance && !_pparam->_vector[path_index][curve_index].is_time) { - if (previous_index) { - amount = _pparam->_vector[path_index][curve_index].lenToRad(amount, pathv[path_index][previous_index], pathv[path_index][curve_index], _pparam->_vector[path_index][previous_index]); - } else { - amount = 0.0; - } + amount = _pparam->_vector[path_index][curve_index].lenToRad(amount, pathv[path_index][previous_index], pathv[path_index][curve_index], _pparam->_vector[path_index][previous_index]); } bool aprox = false; Geom::D2 d2_out = pathv[path_index][curve_index].toSBasis(); - if (previous_index) { - Geom::D2 d2_in = pathv[path_index][previous_index].toSBasis(); - aprox = ((d2_in)[0].degreesOfFreedom() != 2 || - d2_out[0].degreesOfFreedom() != 2) && - !_pparam->_use_distance - ? true - : false; - } + Geom::D2 d2_in = pathv[path_index][previous_index].toSBasis(); + aprox = ((d2_in)[0].degreesOfFreedom() != 2 || + d2_out[0].degreesOfFreedom() != 2) && + !_pparam->_use_distance + ? true + : false; Inkscape::UI::Dialogs::FilletChamferPropertiesDialog::showDialog( this->desktop, amount, this, _pparam->_use_distance, aprox, _pparam->_vector[path_index][curve_index]); @@ -540,10 +546,13 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double amount = satellite.amount; double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { - size_t previous_index = curve_index - 1; + gint previous_index = curve_index - 1; if(curve_index == 0 && pathv[path_index].closed()){ previous_index = pathv[path_index].size() - 1; } + if( previous_index < 0 ) { + return; + } amount = _pparam->_vector[path_index][curve_index].radToLen(amount, pathv[path_index][previous_index], pathv[path_index][curve_index]); if (max_amount > 0 && amount == 0) { amount = _pparam->_vector[path_index][curve_index].amount; diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index c86fc4a20..098a84edf 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 60d4c807f..d02b8e6d3 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(); -- cgit v1.2.3 From 38a1a4d45114a681408e763c3afec79f0bc21940 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 18 Jun 2016 18:53:51 +0200 Subject: fixing bug moving nodes (bzr r13645.1.162) --- src/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 ++++++------- src/live_effects/parameter/satellitesarray.cpp | 7 ++----- src/ui/tools/node-tool.cpp | 2 +- 7 files changed, 35 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index e80d812d7..1f71a2e91 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 515aa26fc..7b36e30f9 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -363,14 +363,13 @@ Effect::Effect(LivePathEffectObject *lpeobject) lpeobj(lpeobject), concatenate_before_pwd2(false), sp_lpe_item(NULL), - current_zoom(1), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden - is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden + is_ready(false), // is automatically set to false if providesOwnFlashPaths() is not overridden + _current_zoom(1.0) { registerParameter( dynamic_cast(&is_visible) ); is_visible.widget_is_visible = false; - current_zoom = 0.0; } Effect::~Effect() @@ -400,13 +399,19 @@ Effect::doOnApply (SPLPEItem const*/*lpeitem*/) } void -Effect::setCurrentZoom(double cZ) +Effect::setCurrentZoom(double zoom) { - current_zoom = cZ; + _current_zoom = zoom; +} + +double +Effect::getCurrentZoom() +{ + return _current_zoom; } void -Effect::setSelectedNodePoints(std::vector selected_nodes_pos) +Effect::setSelectedNodes(std::vector selected_nodes_pos) { _selected_nodes_pos = selected_nodes_pos; } @@ -419,9 +424,9 @@ Effect::getSelectedNodes() for (size_t i = 0; i < pathvector_before_effect.size(); i++) { for (size_t j = 0; j < pathvector_before_effect[i].size_closed(); j++) { if ((!pathvector_before_effect[i].closed() && - pathvector_before_effect[i].size_closed() == j-1 && - isNodePointSelected( pathvector_before_effect[i][j].finalPoint())) || - isNodePointSelected( pathvector_before_effect[i][j].initialPoint())) + pathvector_before_effect[i].size_closed() == j+1 && + isNodeSelected( pathvector_before_effect[i][j].finalPoint())) || + isNodeSelected( pathvector_before_effect[i][j].initialPoint())) { result.push_back(counter); } @@ -433,15 +438,15 @@ Effect::getSelectedNodes() bool -Effect::isNodePointSelected(Geom::Point const &node_point) const +Effect::isNodeSelected(Geom::Point const &node_point) const { if (_selected_nodes_pos.size() > 0) { using Geom::X; using Geom::Y; + Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); for (std::vector::const_iterator i = _selected_nodes_pos.begin(); i != _selected_nodes_pos.end(); ++i) { Geom::Point p = *i; - Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); Geom::Point p2(node_point[X],node_point[Y]); p2 *= transformCoordinate; if (Geom::are_near(p, p2, 0.01)) { diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 3b02b14d4..ac83d9b75 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -58,10 +58,11 @@ public: //of indirection is needed. We first call these methods, then the below. void doOnApply_impl(SPLPEItem const* lpeitem); void doBeforeEffect_impl(SPLPEItem const* lpeitem); - void setCurrentZoom(double cZ); - void setSelectedNodePoints(std::vector selected_nodes_pos); + void setCurrentZoom(double zoom); + double getCurrentZoom(); + void setSelectedNodes(std::vector selected_nodes_pos); std::vector getSelectedNodes(); - bool isNodePointSelected(Geom::Point const &node_point) const; + bool isNodeSelected(Geom::Point const &node_point) const; virtual void doOnApply (SPLPEItem const* lpeitem); virtual void doBeforeEffect (SPLPEItem const* lpeitem); @@ -162,7 +163,6 @@ protected: bool concatenate_before_pwd2; SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. - double current_zoom; std::vector _selected_nodes_pos; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; @@ -170,7 +170,7 @@ private: bool provides_own_flash_paths; // if true, the standard flash path is suppressed bool is_ready; - + double _current_zoom; Effect(const Effect&); Effect& operator=(const Effect&); }; diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index 1423e670a..3fed11d5a 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -398,7 +398,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) (apply_no_weight && Geom::are_near((*cubic)[1], point_at0)) || (apply_with_weight && !Geom::are_near((*cubic)[1], point_at0))) { - if (isNodePointSelected(point_at0) || !only_selected) { + if (isNodeSelected(point_at0) || !only_selected) { point_at1 = sbasis_in.valueAt(weight_ammount); if (weight_ammount != NO_POWER) { point_at1 = @@ -414,7 +414,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) (apply_no_weight && Geom::are_near((*cubic)[2], point_at3)) || (apply_with_weight && !Geom::are_near((*cubic)[2], point_at3))) { - if (isNodePointSelected(point_at3) || !only_selected) { + if (isNodeSelected(point_at3) || !only_selected) { point_at2 = sbasis_in.valueAt(1 - weight_ammount); if (weight_ammount != NO_POWER) { point_at2 = @@ -431,14 +431,14 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) (apply_no_weight && weight_ammount == NO_POWER) || (apply_with_weight && weight_ammount != NO_POWER)) { - if (isNodePointSelected(point_at0) || !only_selected) { + if (isNodeSelected(point_at0) || !only_selected) { point_at1 = sbasis_in.valueAt(weight_ammount); point_at1 = Geom::Point(point_at1[X] + HANDLE_CUBIC_GAP, point_at1[Y] + HANDLE_CUBIC_GAP); } else { point_at1 = in->first_segment()->initialPoint(); } - if (isNodePointSelected(point_at3) || !only_selected) { + if (isNodeSelected(point_at3) || !only_selected) { point_at2 = sbasis_in.valueAt(1 - weight_ammount); point_at2 = Geom::Point(point_at2[X] + HANDLE_CUBIC_GAP, point_at2[Y] + HANDLE_CUBIC_GAP); diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 7a663614b..c9d3d4afd 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -252,7 +252,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } //fillet chamfer specific calls _satellites_param.setUseDistance(_use_knot_distance); - _satellites_param.setCurrentZoom(current_zoom); + _satellites_param.setCurrentZoom(getCurrentZoom()); //mandatory call _satellites_param.setEffectType(effectType()); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); @@ -262,7 +262,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) size_t number_nodes = pathv.nodes().size(); size_t previous_number_nodes = _pathvector_satellites->getPathVector().nodes().size(); if (number_nodes != previous_number_nodes) { - std::cout << "sfsfaasfasfasfasffasdf\n"; Satellite satellite(FILLET); satellite.setIsTime(_flexible); satellite.setHasMirror(_mirror_knots); @@ -348,7 +347,8 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) size_t path = 0; const double K = (4.0 / 3.0) * (sqrt(2.0) - 1.0); _degenerate_hide = false; - Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); + Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(path_in); + Satellites satellites = _pathvector_satellites->getSatellites(); for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { if (path_it->empty()) { continue; @@ -363,7 +363,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } double time0 = 0; size_t curve = 0; - Satellites satellites = _pathvector_satellites->getSatellites(); for (Geom::Path::const_iterator curve_it1 = path_it->begin(); curve_it1 != path_it->end(); ++curve_it1) { size_t next_index = curve + 1; if (curve == pathv[path].size() - 1 && pathv[path].closed()) { @@ -377,8 +376,10 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } continue; } + Geom::Curve const &curve_it2 = pathv[path][next_index]; Satellite satellite = satellites[path][next_index]; - if (Geom::are_near((*curve_it1).initialPoint(),(*curve_it1).finalPoint())) { + if (Geom::are_near((*curve_it1).initialPoint(), (*curve_it1).finalPoint()) || + Geom::are_near(curve_it2.initialPoint(), curve_it2.finalPoint())) { _degenerate_hide = true; g_warning("Knots hidded if consecutive nodes has the same position."); return path_in; @@ -391,7 +392,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } } bool last = pathv[path].size() - 1 == curve; - Geom::Curve const &curve_it2 = pathv[path][next_index]; double s = satellite.arcDistance(curve_it2); double time1 = satellite.time(s, true, (*curve_it1)); double time2 = satellite.time(curve_it2); @@ -406,6 +406,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) times.push_back(time1); times.push_back(time2); Geom::Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); + Geom::Curve *knot_curve_2 = curve_it2.portion(times[2], 1); if (curve > 0) { knot_curve_1->setInitial(tmp_path.finalPoint()); } else { @@ -432,7 +433,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (time0 == 1) { handle_1 = start_arc_point; } - Geom::Curve *knot_curve_2 = curve_it2.portion(times[2], 1); Geom::CubicBezier const *cubic_2 = dynamic_cast(&*knot_curve_2); Geom::Ray ray_2(curve_it2.initialPoint(), end_arc_point); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 71c69c6c5..8c86f64ca 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -356,10 +356,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, _pparam->_knot_reset_helper *= Geom::Affine(_pparam->_helper_size * 0.1,0,0,_pparam->_helper_size * 0.1,0,0) * Geom::Translate(pathv[path_index][curve_index].initialPoint()); } _pparam->_vector[path_index][curve_index] = satellite; - SPLPEItem *splpeitem = dynamic_cast(item); - if (splpeitem) { - sp_lpe_item_update_patheffect(splpeitem, false, false); - } + sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); } Geom::Point FilletChamferKnotHolderEntity::knot_get() const @@ -391,7 +388,6 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const } this->knot->show(); if (is_mirror) { - tmp_point = satellite.getPosition(pathv[path_index][curve_index]); gint previous_index = curve_index - 1; if(curve_index == 0 && pathv[path_index].closed()){ previous_index = pathv[path_index].size() - 1; @@ -418,6 +414,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const tmp_point = satellite.getPosition(pathv[path_index][curve_index]); } Geom::Point const canvas_point = tmp_point; + _pparam->updateCanvasIndicators(); return canvas_point; } diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index d02b8e6d3..6a1feb760 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(); -- cgit v1.2.3 From 6820ee49d69cd419c5e8d3c9de74b0552758c842 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 19 Jun 2016 00:58:42 +0200 Subject: Fixes when moves a path (bzr r13645.1.163) --- src/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 + src/live_effects/parameter/satellitesarray.cpp | 1 - src/ui/tools/node-tool.cpp | 9 +++++---- 6 files changed, 29 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index 1f71a2e91..f72841b30 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 7b36e30f9..5ac5e2407 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -421,6 +421,9 @@ Effect::getSelectedNodes() { size_t counter = 0; std::vector result; + if (pathvector_before_effect.empty()){ + return result; + } for (size_t i = 0; i < pathvector_before_effect.size(); i++) { for (size_t j = 0; j < pathvector_before_effect[i].size_closed(); j++) { if ((!pathvector_before_effect[i].closed() && @@ -440,15 +443,11 @@ Effect::getSelectedNodes() bool Effect::isNodeSelected(Geom::Point const &node_point) const { - if (_selected_nodes_pos.size() > 0) { - using Geom::X; - using Geom::Y; - Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); + if (!_selected_nodes_pos.empty()) { for (std::vector::const_iterator i = _selected_nodes_pos.begin(); i != _selected_nodes_pos.end(); ++i) { - Geom::Point p = *i; - Geom::Point p2(node_point[X],node_point[Y]); - p2 *= transformCoordinate; + Geom::Point p = (*i); + Geom::Point p2(node_point[Geom::X],node_point[Geom::Y]); if (Geom::are_near(p, p2, 0.01)) { return true; } diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index c9d3d4afd..47b91bf03 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -258,26 +258,23 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 + Satellites satellites = _satellites_param.data(); + if(satellites.empty()) { + doOnApply(lpeItem); + satellites = _satellites_param.data(); + } if (_pathvector_satellites) { size_t number_nodes = pathv.nodes().size(); - size_t previous_number_nodes = _pathvector_satellites->getPathVector().nodes().size(); + size_t previous_number_nodes = _pathvector_satellites->getTotalSatellites(); if (number_nodes != previous_number_nodes) { Satellite satellite(FILLET); satellite.setIsTime(_flexible); satellite.setHasMirror(_mirror_knots); satellite.setHidden(_hide_knots); _pathvector_satellites->recalculateForNewPathVector(pathv, satellite); - _pathvector_satellites->setSelected(getSelectedNodes()); - _satellites_param.setPathVectorSatellites(_pathvector_satellites); - refreshKnots(); - return; + satellites = _pathvector_satellites->getSatellites(); } } - Satellites satellites = _satellites_param.data(); - if(satellites.empty()) { - doOnApply(lpeItem); - satellites = _satellites_param.data(); - } if (_degenerate_hide) { _satellites_param.setGlobalKnotHide(true); } else { @@ -311,7 +308,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].hidden = _hide_knots; } } - _pathvector_satellites = new PathVectorSatellites(); + if (!_pathvector_satellites) { + _pathvector_satellites = new PathVectorSatellites(); + } _pathvector_satellites->setPathVector(pathv); _pathvector_satellites->setSatellites(satellites); _pathvector_satellites->setSelected(getSelectedNodes()); @@ -378,8 +377,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) } Geom::Curve const &curve_it2 = pathv[path][next_index]; Satellite satellite = satellites[path][next_index]; - if (Geom::are_near((*curve_it1).initialPoint(), (*curve_it1).finalPoint()) || - Geom::are_near(curve_it2.initialPoint(), curve_it2.finalPoint())) { + if (Geom::are_near((*curve_it1).initialPoint(), (*curve_it1).finalPoint())) { _degenerate_hide = true; g_warning("Knots hidded if consecutive nodes has the same position."); return path_in; diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 134886950..d3f437afd 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -16,6 +16,7 @@ #include "live_effects/parameter/satellitesarray.h" #include "live_effects/effect.h" #include "helper/geom-pathvectorsatellites.h" +#include "helper/geom-satellite.h" namespace Inkscape { namespace LivePathEffect { diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 8c86f64ca..d4182d459 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -81,7 +81,6 @@ void SatellitesArrayParam::setHelperSize(int hs) void SatellitesArrayParam::updateCanvasIndicators(bool mirror) { - if (!_last_pathvector_satellites) { return; } diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 6a1feb760..9bdc578c1 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(); -- cgit v1.2.3 From 417ba16c9f42a5476045ca4f1825fff2fed518ba Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 19 Jun 2016 03:30:10 +0200 Subject: Organize doeffect function (bzr r13645.1.164) --- src/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 +- src/live_effects/parameter/satellitesarray.cpp | 26 ++++---- src/ui/dialog/lpe-fillet-chamfer-properties.cpp | 6 +- 6 files changed, 61 insertions(+), 70 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index f72841b30..eca866978 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 1242c9aaf..8a92273d0 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 47b91bf03..268e08921 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -259,7 +259,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 Satellites satellites = _satellites_param.data(); - if(satellites.empty()) { + if (satellites.empty()) { doOnApply(lpeItem); satellites = _satellites_param.data(); } @@ -290,7 +290,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) if (satellites[i][j].is_time != _flexible) { satellites[i][j].is_time = _flexible; double amount = satellites[i][j].amount; - if (pathv[i].size() == j){ + if (pathv[i].size() == j) { continue; } Geom::Curve const &curve_in = pathv[i][j]; @@ -367,6 +367,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (curve == pathv[path].size() - 1 && pathv[path].closed()) { next_index = 0; } + //append last extreme of paths on open paths if (curve == pathv[path].size() -1 && !pathv[path].closed()) { //the path is open and we are at end of path if (time0 != 1) { //Previous satellite not at 100% amount Geom::Curve *last_curve = curve_it1->portion(time0, 1); @@ -389,7 +390,6 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) time0 = satellites[path][0].time(*curve_it1); } } - bool last = pathv[path].size() - 1 == curve; double s = satellite.arcDistance(curve_it2); double time1 = satellite.time(s, true, (*curve_it1)); double time2 = satellite.time(curve_it2); @@ -399,70 +399,61 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) if (time2 > 1) { time2 = 1; } - std::vector times; - times.push_back(time0); - times.push_back(time1); - times.push_back(time2); - Geom::Curve *knot_curve_1 = curve_it1->portion(times[0], times[1]); - Geom::Curve *knot_curve_2 = curve_it2.portion(times[2], 1); + Geom::Curve *knot_curve_1 = curve_it1->portion(time0, time1); + Geom::Curve *knot_curve_2 = curve_it2.portion(time2, 1); if (curve > 0) { knot_curve_1->setInitial(tmp_path.finalPoint()); } else { - tmp_path.start((*curve_it1).pointAt(times[0])); + tmp_path.start((*curve_it1).pointAt(time0)); } Geom::Point start_arc_point = knot_curve_1->finalPoint(); - Geom::Point end_arc_point = curve_it2.pointAt(times[2]); - if (times[2] == 1) { - end_arc_point = curve_it2.pointAt(times[2] - GAP_HELPER); + Geom::Point end_arc_point = curve_it2.pointAt(time2); + //add a gap helper + if (time2 == 1) { + end_arc_point = curve_it2.pointAt(time2 - GAP_HELPER); } - if (times[1] == times[0]) { - start_arc_point = curve_it1->pointAt(times[0] + GAP_HELPER); + if (time1 == time0) { + start_arc_point = curve_it1->pointAt(time1 + GAP_HELPER); } + double k1 = distance(start_arc_point, curve_it1->finalPoint()) * K; - double k2 = distance(end_arc_point, curve_it2.initialPoint()) * K; - Geom::CubicBezier const *cubic_1 = - dynamic_cast(&*knot_curve_1); + double k2 = distance(curve_it2.initialPoint(), end_arc_point) * K; + Geom::CubicBezier const *cubic_1 = dynamic_cast(&*knot_curve_1); + Geom::CubicBezier const *cubic_2 = dynamic_cast(&*knot_curve_2); Geom::Ray ray_1(start_arc_point, curve_it1->finalPoint()); + Geom::Ray ray_2(curve_it2.initialPoint(), end_arc_point); if (cubic_1) { ray_1.setPoints((*cubic_1)[2], start_arc_point); } - Geom::Point handle_1 = Geom::Point::polar(ray_1.angle(), k1) + start_arc_point; - if (time0 == 1) { - handle_1 = start_arc_point; - } - Geom::CubicBezier const *cubic_2 = - dynamic_cast(&*knot_curve_2); - Geom::Ray ray_2(curve_it2.initialPoint(), end_arc_point); if (cubic_2) { ray_2.setPoints(end_arc_point, (*cubic_2)[1]); } - Geom::Point handle_2 = end_arc_point - Geom::Point::polar(ray_2.angle(), k2); - - bool ccw_toggle = cross(curve_it1->finalPoint() - start_arc_point, - end_arc_point - start_arc_point) < 0; + bool ccw_toggle = cross(curve_it1->finalPoint() - start_arc_point, end_arc_point - start_arc_point) < 0; double angle = angle_between(ray_1, ray_2, ccw_toggle); - double handleAngle = ray_1.angle() - angle; + double handle_angle_1 = ray_1.angle() - angle; + double handle_angle_2 = ray_2.angle() + angle; if (ccw_toggle) { - handleAngle = ray_1.angle() + angle; + handle_angle_1 = ray_1.angle() + angle; + handle_angle_2 = ray_2.angle() - angle; } - Geom::Point inverse_handle_1 = Geom::Point::polar(handleAngle, k1) + start_arc_point; + Geom::Point handle_1 = Geom::Point::polar(ray_1.angle(), k1) + start_arc_point; + Geom::Point handle_2 = end_arc_point - Geom::Point::polar(ray_2.angle(), k2); + Geom::Point inverse_handle_1 = Geom::Point::polar(handle_angle_1, k1) + start_arc_point; + Geom::Point inverse_handle_2 = end_arc_point - Geom::Point::polar(handle_angle_2, k2); if (time0 == 1) { + handle_1 = start_arc_point; inverse_handle_1 = start_arc_point; } - handleAngle = ray_2.angle() + angle; - if (ccw_toggle) { - handleAngle = ray_2.angle() - angle; - } - Geom::Point inverse_handle_2 = end_arc_point - Geom::Point::polar(handleAngle, k2); - if (times[2] == 1) { - end_arc_point = curve_it2.pointAt(times[2]); + //remove gap helper + if (time2 == 1) { + end_arc_point = curve_it2.pointAt(time2); } - if (times[1] == times[0]) { - start_arc_point = curve_it1->pointAt(times[0]); + if (time1 == time0) { + start_arc_point = curve_it1->pointAt(time0); } - if (times[1] != 1) { - if (times[1] != times[0] || (times[1] == 1 && times[0] == 1)) { + if (time1 != 1) { + if (time1 != time0 || (time1 == 1 && time0 == 1)) { if (!knot_curve_1->isDegenerate()) { tmp_path.append(*knot_curve_1); } @@ -474,7 +465,7 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Line const angled_line(start_arc_point, end_arc_point); double arc_angle = Geom::angle_between(x_line, angled_line); double radius = Geom::distance(start_arc_point, middle_point(start_arc_point, end_arc_point)) / - sin(angle / 2.0); + sin(angle / 2.0); Geom::Coord rx = radius; Geom::Coord ry = rx; bool eliptical = (is_straight_curve(*curve_it1) && @@ -531,11 +522,11 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) tmp_path.append(*knot_curve_1); } } - if (path_it->closed() && last) { - tmp_path.close(); - } curve++; - time0 = times[2]; + time0 = time2; + } + if (path_it->closed()) { + tmp_path.close(); } path++; path_out.push_back(tmp_path); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 28867def2..7470f54cd 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -59,7 +59,7 @@ ArrayParam >::readsvg(const gchar * str) gchar ** iter = strarray; while (*iter != NULL) { gchar ** strsubarray = g_strsplit(*iter, ",", 8); - if(*strsubarray[7]){//steps always > 0 + if (*strsubarray[7]) {//steps always > 0 Satellite *satellite = new Satellite(); satellite->setSatelliteType(g_strstrip(strsubarray[0])); satellite->is_time = strncmp(strsubarray[1],"1",1) == 0; diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index d4182d459..4705fd821 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -85,7 +85,7 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) return; } - if(!_hp.empty()) { + if (!_hp.empty()) { _hp.clear(); } Geom::PathVector pathv = _last_pathvector_satellites->getPathVector(); @@ -112,10 +112,10 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) double size_out = _vector[i][j].arcDistance(*curve_in); double lenght_out = curve_in->length(); gint previous_index = j - 1; //Always are previous index because we skip first satellite on open paths - if(j == 0 && pathv[i].closed()){ + if (j == 0 && pathv[i].closed()) { previous_index = pathv[i].size() - 1; } - if( previous_index < 0 ) { + if ( previous_index < 0 ) { return; } double lenght_in = pathv.curveAt(previous_index).length(); @@ -188,7 +188,7 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) } } } - if(!_knot_reset_helper.empty()){ + if (!_knot_reset_helper.empty()) { _hp.insert(_hp.end(), _knot_reset_helper.begin(), _knot_reset_helper.end() ); } if (mirror) { @@ -314,10 +314,10 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, return; } gint previous_index = curve_index - 1; - if(curve_index == 0 && pathv[path_index].closed()){ + if (curve_index == 0 && pathv[path_index].closed()) { previous_index = pathv[path_index].size() - 1; } - if( previous_index < 0 ) { + if ( previous_index < 0 ) { return; } Geom::Curve const &curve_in = pathv[path_index][previous_index]; @@ -346,7 +346,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, satellite.setPosition(s, pathv[path_index][curve_index]); } _pparam->_knot_reset_helper.clear(); - if (satellite.amount == 0){ + if (satellite.amount == 0) { char const *svgd; svgd = "M -5.39,8.78 -9.13,5.29 -10.38,10.28 Z M -7.22,7.07 -3.43,3.37 m -1.95,-12.16 -3.74,3.5 -1.26,-5 z " "m -1.83,1.71 3.78,3.7 M 5.24,8.78 8.98,5.29 10.24,10.28 Z " @@ -388,10 +388,10 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const this->knot->show(); if (is_mirror) { gint previous_index = curve_index - 1; - if(curve_index == 0 && pathv[path_index].closed()){ + if (curve_index == 0 && pathv[path_index].closed()) { previous_index = pathv[path_index].size() - 1; } - if( previous_index < 0 ) { + if ( previous_index < 0 ) { return Geom::Point(Geom::infinity(), Geom::infinity()); } Geom::Curve const &curve_in = pathv[path_index][previous_index]; @@ -490,10 +490,10 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } else if (state & GDK_SHIFT_MASK) { double amount = _pparam->_vector[path_index][curve_index].amount; gint previous_index = curve_index - 1; - if(curve_index == 0 && pathv[path_index].closed()){ + if (curve_index == 0 && pathv[path_index].closed()) { previous_index = pathv[path_index].size() - 1; } - if( previous_index < 0 ) { + if ( previous_index < 0 ) { return; } if (!_pparam->_use_distance && !_pparam->_vector[path_index][curve_index].is_time) { @@ -543,10 +543,10 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) double max_amount = amount; if (!_pparam->_use_distance && !satellite.is_time) { gint previous_index = curve_index - 1; - if(curve_index == 0 && pathv[path_index].closed()){ + if (curve_index == 0 && pathv[path_index].closed()) { previous_index = pathv[path_index].size() - 1; } - if( previous_index < 0 ) { + if ( previous_index < 0 ) { return; } amount = _pparam->_vector[path_index][curve_index].radToLen(amount, pathv[path_index][previous_index], pathv[path_index][curve_index]); diff --git a/src/ui/dialog/lpe-fillet-chamfer-properties.cpp b/src/ui/dialog/lpe-fillet-chamfer-properties.cpp index 098a84edf..98b654640 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) { -- cgit v1.2.3 From d431044fc72f9b668dcfa5771f361f4d6088bdd7 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 22 Jan 2017 18:53:31 +0100 Subject: Update to new code in trunk (bzr r13645.1.166) --- src/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 ++-- src/live_effects/parameter/satellitesarray.cpp | 8 +- src/live_effects/parameter/satellitesarray.h | 9 +- src/ui/tools/node-tool.cpp | 4 +- 9 files changed, 214 insertions(+), 157 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index eca866978..79055af8d 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 4a020f553..d86e6cb25 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 6899a3161..19e80c611 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -119,7 +119,7 @@ const Util::EnumData LPETypeData[] = { /* 0.92 */ {SIMPLIFY, N_("Simplify"), "simplify"}, {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, - {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"}, + {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective_envelope"}, {INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"}, {TRANSFORM_2PTS, N_("Transform by 2 points"), "transform_2pts"}, {SHOW_HANDLES, N_("Show handles"), "show_handles"}, @@ -129,7 +129,6 @@ const Util::EnumData LPETypeData[] = { {TAPER_STROKE, N_("Taper stroke"), "taper_stroke"}, {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, - {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"}, /* Ponyscape -> Inkscape 0.92*/ {ATTACH_PATH, N_("Attach path"), "attach_path"}, {FILL_BETWEEN_STROKES, N_("Fill between strokes"), "fill_between_strokes"}, @@ -137,7 +136,8 @@ const Util::EnumData LPETypeData[] = { {ELLIPSE_5PTS, N_("Ellipse by 5 points"), "ellipse_5pts"}, {BOUNDING_BOX, N_("Bounding Box"), "bounding_box"}, /* 9.93 */ - {MEASURE_LINE, N_("Measure Line"), "measure-line"}, + {MEASURE_LINE, N_("Measure Line"), "measure_line"}, + {FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet_chamfer"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData)); @@ -358,11 +358,11 @@ Effect::Effect(LivePathEffectObject *lpeobject) upd_params(true), sp_curve(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden - is_ready(false), // is automatically set to false if providesOwnFlashPaths() is not overridden - _current_zoom(1.0) + is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden { registerParameter( dynamic_cast(&is_visible) ); is_visible.widget_is_visible = false; + current_zoom = 0.0; } Effect::~Effect() @@ -392,55 +392,67 @@ Effect::doOnApply (SPLPEItem const*/*lpeitem*/) } void -Effect::setCurrentZoom(double zoom) +Effect::setSelectedNodePos(std::vector selected_nodes_pos_data) { - _current_zoom = zoom; -} - -double -Effect::getCurrentZoom() -{ - return _current_zoom; + selected_nodes_pos = selected_nodes_pos_data; } void -Effect::setSelectedNodes(std::vector selected_nodes_pos) +Effect::setSelectedNodeIndex(Geom::PathVector pv) { - _selected_nodes_pos = selected_nodes_pos; -} + selected_nodes_index.clear(); + for (Geom::PathVector::const_iterator path_it = pv.begin(); + path_it != pv.end(); ++path_it) { -std::vector -Effect::getSelectedNodes() -{ - size_t counter = 0; - std::vector result; - if (pathvector_before_effect.empty()){ - return result; - } - for (size_t i = 0; i < pathvector_before_effect.size(); i++) { - for (size_t j = 0; j < pathvector_before_effect[i].size_closed(); j++) { - if ((!pathvector_before_effect[i].closed() && - pathvector_before_effect[i].size_closed() == j+1 && - isNodeSelected( pathvector_before_effect[i][j].finalPoint())) || - isNodeSelected( pathvector_before_effect[i][j].initialPoint())) - { - result.push_back(counter); + if (path_it->empty()) { + continue; + } + Geom::Path::const_iterator curve_it1 = path_it->begin(); + Geom::Path::const_iterator curve_endit = path_it->end_default(); + if (path_it->closed()) { + const Geom::Curve &closingline = path_it->back_closed(); + // the closing line segment is always of type + // Geom::LineSegment. + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + // closingline.isDegenerate() did not work, because it only checks for + // *exact* zero length, which goes wrong for relative coordinates and + // rounding errors... + // the closing line segment has zero-length. So stop before that one! + curve_endit = path_it->end_open(); + } + } + size_t i = 0; + while (curve_it1 != curve_endit) { + if (isNodeSelected(curve_it1->initialPoint())) { + selected_nodes_index.push_back(i); } - counter++; + ++i; + ++curve_it1; + } + if (isNodeSelected(path_it->finalPoint())) { + selected_nodes_index.push_back(i); } } - return result; } +void +Effect::setCurrentZoom(double cZ) +{ + current_zoom = cZ; +} bool -Effect::isNodeSelected(Geom::Point const &node_point) const -{ - if (!_selected_nodes_pos.empty()) { - for (std::vector::const_iterator i = _selected_nodes_pos.begin(); - i != _selected_nodes_pos.end(); ++i) { - Geom::Point p = (*i); - Geom::Point p2(node_point[Geom::X],node_point[Geom::Y]); +Effect::isNodeSelected(Geom::Point const &nodePoint) const +{ + if (selected_nodes_pos.size() > 0) { + using Geom::X; + using Geom::Y; + for (std::vector::const_iterator i = selected_nodes_pos.begin(); + i != selected_nodes_pos.end(); ++i) { + Geom::Point p = *i; + Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); + Geom::Point p2(nodePoint[X],nodePoint[Y]); + p2 *= transformCoordinate; if (Geom::are_near(p, p2, 0.01)) { return true; } diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 61de60db8..0190325c0 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -58,11 +58,10 @@ public: //of indirection is needed. We first call these methods, then the below. void doOnApply_impl(SPLPEItem const* lpeitem); void doBeforeEffect_impl(SPLPEItem const* lpeitem); - void setCurrentZoom(double zoom); - double getCurrentZoom(); - void setSelectedNodes(std::vector selected_nodes_pos); - std::vector getSelectedNodes(); - bool isNodeSelected(Geom::Point const &node_point) const; + void setCurrentZoom(double cZ); + void setSelectedNodePos(std::vector selected_nodes_pos_data); + void setSelectedNodeIndex(Geom::PathVector pv); + bool isNodeSelected(Geom::Point const &nodePoint) const; virtual void doOnApply (SPLPEItem const* lpeitem); virtual void doBeforeEffect (SPLPEItem const* lpeitem); @@ -166,14 +165,16 @@ protected: bool concatenate_before_pwd2; SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. - std::vector _selected_nodes_pos; + double current_zoom; + std::vector selected_nodes_pos; + std::vector selected_nodes_index; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; private: bool provides_own_flash_paths; // if true, the standard flash path is suppressed bool is_ready; - double _current_zoom; + Effect(const Effect&); Effect& operator=(const Effect&); }; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 2bbd3dbab..410d6f0fc 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -23,65 +23,68 @@ namespace Inkscape { namespace LivePathEffect { -static const Util::EnumData Fillet_methodData[] = { +static const Util::EnumData FilletmethodData[] = { { FM_AUTO, N_("Auto"), "auto" }, { FM_ARC, N_("Force arc"), "arc" }, { FM_BEZIER, N_("Force bezier"), "bezier" } }; -static const Util::EnumDataConverter FMConverter(Fillet_methodData, FM_END); +static const Util::EnumDataConverter FMConverter(FilletmethodData, FM_END); LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - _satellites_param("satellites_param", "satellites_param", - "_satellites_param", &wr, this), - _method(_("_method:"), _("_methods to calculate the fillet or chamfer"), - "_method", FMConverter, &wr, this, FM_AUTO), - _radius(_("_radius (unit or %):"), _("_radius, in unit or %"), "_radius", &wr, + unit(_("Unit"), _("Unit"), "unit", &wr, this, "px"), + satellites_param("Satellites_param", "Satellites_param", + "satellites_param", &wr, this), + method(_("Method:"), _("Methods to calculate the fillet or chamfer"), + "method", FMConverter, &wr, this, FM_AUTO), + radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.0), - _chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "_chamfer_steps", + chamfer_steps(_("Chamfer steps:"), _("Chamfer steps"), "chamfer_steps", &wr, this, 1), - _flexible(_("_flexible _radius size (%)"), _("_flexible _radius size (%)"), - "_flexible", &wr, this, false), - _mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "_mirror_knots", &wr, + flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), + "flexible", &wr, this, false), + mirror_knots(_("Mirror Knots"), _("Mirror Knots"), "mirror_knots", &wr, this, true), - _only_selected(_("Change only selected nodes"), - _("Change only selected nodes"), "_only_selected", &wr, this, + only_selected(_("Change only selected nodes"), + _("Change only selected nodes"), "only_selected", &wr, this, false), - _use_knot_distance(_("Use knots distance instead _radius"), - _("Use knots distance instead _radius"), - "_use_knot_distance", &wr, this, false), - _hide_knots(_("Hide knots"), _("Hide knots"), "_hide_knots", &wr, this, + use_knot_distance(_("Use knots distance instead radius"), + _("Use knots distance instead radius"), + "use_knot_distance", &wr, this, false), + hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), - _apply_no_radius(_("Apply changes if _radius = 0"), _("Apply changes if _radius = 0"), "_apply_no_radius", &wr, this, true), - _apply_with_radius(_("Apply changes if _radius > 0"), _("Apply changes if _radius > 0"), "_apply_with_radius", &wr, this, true), - _helper_size(_("Helper path size with direction to node:"), - _("Helper path size with direction to node"), "_helper_size", &wr, this, 0), + apply_no_radius(_("Apply changes if radius = 0"), _("Apply changes if radius = 0"), "apply_no_radius", &wr, this, true), + apply_with_radius(_("Apply changes if radius > 0"), _("Apply changes if radius > 0"), "apply_with_radius", &wr, this, true), + helper_size(_("Helper path size with direction to node:"), + _("Helper path size with direction to node"), "helper_size", &wr, this, 0), _pathvector_satellites(NULL), _degenerate_hide(false) { - registerParameter(&_satellites_param); - registerParameter(&_method); - registerParameter(&_radius); - registerParameter(&_chamfer_steps); - registerParameter(&_helper_size); - registerParameter(&_flexible); - registerParameter(&_use_knot_distance); - registerParameter(&_mirror_knots); - registerParameter(&_apply_no_radius); - registerParameter(&_apply_with_radius); - registerParameter(&_only_selected); - registerParameter(&_hide_knots); + registerParameter(&satellites_param); + registerParameter(&unit); + registerParameter(&method); + registerParameter(&radius); + registerParameter(&chamfer_steps); + registerParameter(&helper_size); + registerParameter(&flexible); + registerParameter(&use_knot_distance); + registerParameter(&mirror_knots); + registerParameter(&apply_no_radius); + registerParameter(&apply_with_radius); + registerParameter(&only_selected); + registerParameter(&hide_knots); - _radius.param_set_range(0.0, Geom::infinity()); - _radius.param_set_increments(1, 1); - _radius.param_set_digits(4); - _radius.param_overwrite_widget(true); - _chamfer_steps.param_set_range(1, 999); - _chamfer_steps.param_set_increments(1, 1); - _chamfer_steps.param_set_digits(0); - _helper_size.param_set_range(0, 999); - _helper_size.param_set_increments(5, 5); - _helper_size.param_set_digits(0); + radius.param_set_range(0.0, Geom::infinity()); + radius.param_set_increments(1, 1); + radius.param_set_digits(4); + radius.param_overwrite_widget(true); + chamfer_steps.param_set_range(1, 999); + chamfer_steps.param_set_increments(1, 1); + chamfer_steps.param_set_digits(0); + helper_size.param_set_range(0, 999); + helper_size.param_set_increments(5, 5); + helper_size.param_set_digits(0); + _provides_knotholder_entities = true; } void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) @@ -102,16 +105,16 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) // continue //} Satellite satellite(FILLET); - satellite.setSteps(_chamfer_steps); + satellite.setSteps(chamfer_steps); subpath_satellites.push_back(satellite); } //we add the last satellite on open path because _pathvector_satellites is related to nodes, not curves //so maybe in the future we can need this last satellite in other effects - //dont remove for this effect because _pathvector_satellites class has _methods when the path is modiffied - //and we want one _method for all uses + //dont remove for this effect because _pathvector_satellites class has methods when the path is modiffied + //and we want one method for all uses if (!path_it->closed()) { Satellite satellite(FILLET); - satellite.setSteps(_chamfer_steps); + satellite.setSteps(chamfer_steps); subpath_satellites.push_back(satellite); } satellites.push_back(subpath_satellites); @@ -119,7 +122,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) _pathvector_satellites = new PathVectorSatellites(); _pathvector_satellites->setPathVector(pathv); _pathvector_satellites->setSatellites(satellites); - _satellites_param.setPathVectorSatellites(_pathvector_satellites); + satellites_param.setPathVectorSatellites(_pathvector_satellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem *item = const_cast(lpeItem); @@ -141,7 +144,7 @@ Gtk::Widget *LPEFilletChamfer::newWidget() if ((*it)->widget_is_visible) { Parameter *param = *it; Gtk::Widget *widg = param->param_newWidget(); - if (param->param_key == "_radius") { + if (param->param_key == "radius") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); widg_registered->signal_value_changed().connect( @@ -153,7 +156,14 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(6); } - } else if (param->param_key == "_chamfer_steps") { +// } else if (param->param_key == "unit") { +// Inkscape::UI::Widget::RegisteredUnitMenu* widg_registered = +// Gtk::manage(dynamic_cast< Inkscape::UI::Widget::RegisteredUnitMenu *>(widg)); +// widg_registered->setUnit(unit.get_abbreviation()); +// widg_registered->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change unit parameter")); +// widg_registered->getUnitMenu()->signal_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::convertUnit)); +// widg = widg_registered; + } else if (param->param_key == "chamfer_steps") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); widg_registered->signal_value_changed().connect( @@ -165,12 +175,12 @@ Gtk::Widget *LPEFilletChamfer::newWidget() Gtk::Entry *entry_widget = dynamic_cast(childList[1]); entry_widget->set_width_chars(3); } - } else if (param->param_key == "_helper_size") { + } else if (param->param_key == "helper_size") { Inkscape::UI::Widget::Scalar *widg_registered = Gtk::manage(dynamic_cast(widg)); widg_registered->signal_value_changed().connect( sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots)); - } else if (param->param_key == "_only_selected") { + } else if (param->param_key == "only_selected") { Gtk::manage(widg); } Glib::ustring *tip = param->param_getTooltip(); @@ -217,28 +227,37 @@ Gtk::Widget *LPEFilletChamfer::newWidget() void LPEFilletChamfer::refreshKnots() { - if (_satellites_param._knoth) { - _satellites_param._knoth->update_knots(); + if (satellites_param._knoth) { + satellites_param._knoth->update_knots(); } } void LPEFilletChamfer::updateAmount() { - _pathvector_satellites->updateAmount(_radius, _apply_no_radius, _apply_with_radius, _only_selected, - _use_knot_distance, _flexible); - _satellites_param.setPathVectorSatellites(_pathvector_satellites); + _pathvector_satellites->updateAmount(radius, apply_no_radius, apply_with_radius, only_selected, + use_knot_distance, flexible); + satellites_param.setPathVectorSatellites(_pathvector_satellites); } +//void LPEFilletChamfer::convertUnit() +//{ +// SPDocument * document = SP_ACTIVE_DOCUMENT; +// SPNamedView *nv = sp_document_namedview(document, NULL); +// Glib::ustring display_unit = nv->display_units->abbr; +// _pathvector_satellites->convertUnit(unit.get_abbreviation(), display_unit, apply_no_radius, apply_with_radius); +// satellites_param.setPathVectorSatellites(_pathvector_satellites); +//} + void LPEFilletChamfer::updateChamferSteps() { - _pathvector_satellites->updateSteps(_chamfer_steps, _apply_no_radius, _apply_with_radius, _only_selected); - _satellites_param.setPathVectorSatellites(_pathvector_satellites); + _pathvector_satellites->updateSteps(chamfer_steps, apply_no_radius, apply_with_radius, only_selected); + satellites_param.setPathVectorSatellites(_pathvector_satellites); } void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { - _pathvector_satellites->updateSatelliteType(satellitetype, _apply_no_radius, _apply_with_radius, _only_selected); - _satellites_param.setPathVectorSatellites(_pathvector_satellites); + _pathvector_satellites->updateSatelliteType(satellitetype, apply_no_radius, apply_with_radius, only_selected); + satellites_param.setPathVectorSatellites(_pathvector_satellites); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -252,44 +271,44 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } //fillet chamfer specific calls - _satellites_param.setUseDistance(_use_knot_distance); - _satellites_param.setCurrentZoom(getCurrentZoom()); + satellites_param.setUseDistance(use_knot_distance); + satellites_param.setCurrentZoom(current_zoom); //mandatory call - _satellites_param.setEffectType(effectType()); + satellites_param.setEffectType(effectType()); Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); //if are diferent sizes call to poinwise recalculate //TODO: Update the satellite data in paths modified, Goal 0.93 - Satellites satellites = _satellites_param.data(); + Satellites satellites = satellites_param.data(); if (satellites.empty()) { doOnApply(lpeItem); - satellites = _satellites_param.data(); + satellites = satellites_param.data(); } if (_pathvector_satellites) { size_t number_nodes = pathv.nodes().size(); size_t previous_number_nodes = _pathvector_satellites->getTotalSatellites(); if (number_nodes != previous_number_nodes) { Satellite satellite(FILLET); - satellite.setIsTime(_flexible); - satellite.setHasMirror(_mirror_knots); - satellite.setHidden(_hide_knots); + satellite.setIsTime(flexible); + satellite.setHasMirror(mirror_knots); + satellite.setHidden(hide_knots); _pathvector_satellites->recalculateForNewPathVector(pathv, satellite); satellites = _pathvector_satellites->getSatellites(); } } if (_degenerate_hide) { - _satellites_param.setGlobalKnotHide(true); + satellites_param.setGlobalKnotHide(true); } else { - _satellites_param.setGlobalKnotHide(false); + satellites_param.setGlobalKnotHide(false); } - if (_hide_knots) { - _satellites_param.setHelperSize(0); + if (hide_knots) { + satellites_param.setHelperSize(0); } else { - _satellites_param.setHelperSize(_helper_size); + satellites_param.setHelperSize(helper_size); } for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { - if (satellites[i][j].is_time != _flexible) { - satellites[i][j].is_time = _flexible; + if (satellites[i][j].is_time != flexible) { + satellites[i][j].is_time = flexible; double amount = satellites[i][j].amount; if (pathv[i].size() == j) { continue; @@ -303,10 +322,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].amount = size; } } - if (satellites[i][j].has_mirror != _mirror_knots) { - satellites[i][j].has_mirror = _mirror_knots; + if (satellites[i][j].has_mirror != mirror_knots) { + satellites[i][j].has_mirror = mirror_knots; } - satellites[i][j].hidden = _hide_knots; + satellites[i][j].hidden = hide_knots; } } if (!_pathvector_satellites) { @@ -314,8 +333,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } _pathvector_satellites->setPathVector(pathv); _pathvector_satellites->setSatellites(satellites); - _pathvector_satellites->setSelected(getSelectedNodes()); - _satellites_param.setPathVectorSatellites(_pathvector_satellites); + if (only_selected) { + setSelectedNodeIndex(pathv); + _pathvector_satellites->setSelected(selected_nodes_index); + } + satellites_param.setPathVectorSatellites(_pathvector_satellites); refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); @@ -470,8 +492,8 @@ LPEFilletChamfer::doEffect_path(Geom::PathVector const &path_in) Geom::Coord rx = radius; Geom::Coord ry = rx; bool eliptical = (is_straight_curve(*curve_it1) && - is_straight_curve(curve_it2) && _method != FM_BEZIER) || - _method == FM_ARC; + is_straight_curve(curve_it2) && method != FM_BEZIER) || + method == FM_ARC; switch (type) { case CHAMFER: { diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index d3f437afd..2cee04a1e 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -15,13 +15,14 @@ #include "live_effects/parameter/enum.h" #include "live_effects/parameter/satellitesarray.h" #include "live_effects/effect.h" +#include "live_effects/parameter/unit.h" #include "helper/geom-pathvectorsatellites.h" #include "helper/geom-satellite.h" namespace Inkscape { namespace LivePathEffect { -enum Fillet_method { +enum Filletmethod { FM_AUTO, FM_ARC, FM_BEZIER, @@ -39,24 +40,26 @@ public: void addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point, size_t steps); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(SatelliteType satellitetype); + //void convertUnit(); void updateChamferSteps(); void updateAmount(); void refreshKnots(); - SatellitesArrayParam _satellites_param; + SatellitesArrayParam satellites_param; private: - EnumParam _method; - ScalarParam _radius; - ScalarParam _chamfer_steps; - BoolParam _flexible; - BoolParam _mirror_knots; - BoolParam _only_selected; - BoolParam _use_knot_distance; - BoolParam _hide_knots; - BoolParam _apply_no_radius; - BoolParam _apply_with_radius; - ScalarParam _helper_size; + UnitParam unit; + EnumParam method; + ScalarParam radius; + ScalarParam chamfer_steps; + BoolParam flexible; + BoolParam mirror_knots; + BoolParam only_selected; + BoolParam use_knot_distance; + BoolParam hide_knots; + BoolParam apply_no_radius; + BoolParam apply_with_radius; + ScalarParam helper_size; bool _degenerate_hide; PathVectorSatellites *_pathvector_satellites; Geom::PathVector _hp; diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 4705fd821..7efe5dd98 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -223,7 +223,6 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, } void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, SPItem *item, bool mirror) { @@ -260,23 +259,22 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, "Ctrl+Alt+Click reset"); } FilletChamferKnotHolderEntity *e = new FilletChamferKnotHolderEntity(this, index); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip),_knot_shape, _knot_mode, _knot_color); + e->create(NULL, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip),_knot_shape, _knot_mode, _knot_color); knotholder->add(e); } index++; } } if (mirror) { - addKnotHolderEntities(knotholder, desktop, item, false); + addKnotHolderEntities(knotholder, item, false); } } void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, SPItem *item) { _knoth = knotholder; - addKnotHolderEntities(knotholder, desktop, item, true); + addKnotHolderEntities(knotholder, item, true); } FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity( diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index 5b2d8a799..edaf2f08d 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -41,12 +41,9 @@ public: return NULL; } virtual void setHelperSize(int hs); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item); - virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, - SPItem *item, bool mirror); - virtual void addCanvasIndicators(SPLPEItem const *lpeitem, - std::vector &hp_vec); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item); + virtual void addKnotHolderEntities(KnotHolder *knotholder, SPItem *item, bool mirror); + virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec); virtual void updateCanvasIndicators(); virtual void updateCanvasIndicators(bool mirror); virtual bool providesKnotHolderEntities() const diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 94e684bc4..8561e234f 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())); -- cgit v1.2.3 From 98c50c48230463cb059434ad781ccef2ce998cb7 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 16 Mar 2017 20:58:19 +0100 Subject: Remove some warnings (bzr r13645.1.171) --- src/live_effects/parameter/satellitesarray.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 7efe5dd98..8cf517852 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -102,7 +102,7 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror) (!_vector[i][j].has_mirror && mirror == true) || //Ignore if not have mirror and we are in mirror loop _vector[i][j].amount == 0 || //no helper in 0 value pathv[i].size() == j || //ignore last satellite in open paths with fillet chamfer effect - !pathv[i].closed() && j == 0) //ignore first satellites on open paths + (!pathv[i].closed() && j == 0)) //ignore first satellites on open paths { continue; } @@ -306,7 +306,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p, Satellite satellite = _pparam->_vector[path_index][curve_index]; Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); if (satellite.hidden || - !pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + (!pathv[path_index].closed() && curve_index == 0) ||//ignore first satellites on open paths pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return; -- cgit v1.2.3 From 5997087db8a3bc2ec3b3bb0623f3f66cb81a4521 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 16 Mar 2017 21:03:59 +0100 Subject: Remove some warnings (bzr r13645.1.172) --- src/live_effects/parameter/satellitesarray.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index 8cf517852..c7bc7f026 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -378,7 +378,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const Satellite satellite = _pparam->_vector[path_index][curve_index]; Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); if (satellite.hidden || - !pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + (!pathv[path_index].closed() && curve_index == 0) ||//ignore first satellites on open paths pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return Geom::Point(Geom::infinity(), Geom::infinity()); @@ -434,7 +434,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) return; } Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); - if (!pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + if ((!pathv[path_index].closed() && curve_index == 0) ||//ignore first satellites on open paths pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return; @@ -532,7 +532,7 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) } Geom::PathVector pathv = _pparam->_last_pathvector_satellites->getPathVector(); if (satellite.hidden || - !pathv[path_index].closed() && curve_index == 0 ||//ignore first satellites on open paths + (!pathv[path_index].closed() && curve_index == 0) ||//ignore first satellites on open paths pathv[path_index].size() == curve_index) //ignore last satellite in open paths with fillet chamfer effect { return; -- cgit v1.2.3 From 575d7a8f668987ea8395643a2c89a848ba527483 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 02:27:58 +0200 Subject: Updating code to trunk (bzr r13645.1.176) --- src/helper/Makefile_insert.THIS | 49 --------------------------------- src/live_effects/lpe-fillet-chamfer.cpp | 1 - 2 files changed, 50 deletions(-) delete mode 100644 src/helper/Makefile_insert.THIS (limited to 'src') diff --git a/src/helper/Makefile_insert.THIS b/src/helper/Makefile_insert.THIS deleted file mode 100644 index 6ba0efbfa..000000000 --- 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 b9e96cb72..abb6fa9d2 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -305,7 +305,6 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { satellites_param.setHelperSize(helper_size); } - std::vector selected_nodes_index; size_t index = 0; for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { -- cgit v1.2.3 From 5004996c798cdbad5ff7abbaf2e7272411631cee Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sat, 6 May 2017 19:45:16 +0200 Subject: Pre merge fixing (bzr r13645.1.177) --- src/helper/geom-pathvectorsatellites.cpp | 5 ++- src/live_effects/lpe-fillet-chamfer.cpp | 56 ++++++++++++++++---------- src/live_effects/lpe-fillet-chamfer.h | 3 +- src/live_effects/parameter/satellitesarray.cpp | 15 ++++--- src/live_effects/parameter/satellitesarray.h | 2 +- 5 files changed, 51 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/helper/geom-pathvectorsatellites.cpp b/src/helper/geom-pathvectorsatellites.cpp index dd231d78f..e995c0a9b 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 abb6fa9d2..e968a7822 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -234,7 +234,15 @@ void LPEFilletChamfer::refreshKnots() void LPEFilletChamfer::updateAmount() { - _pathvector_satellites->updateAmount(radius, apply_no_radius, apply_with_radius, only_selected, + setSelected(_pathvector_satellites); + double power = radius; + if (!flexible) { + SPDocument * document = SP_ACTIVE_DOCUMENT; + SPNamedView *nv = sp_document_namedview(document, NULL); + Glib::ustring display_unit = nv->display_units->abbr; + power = Inkscape::Util::Quantity::convert(power, unit.get_abbreviation(), display_unit.c_str()); + } + _pathvector_satellites->updateAmount(power, apply_no_radius, apply_with_radius, only_selected, use_knot_distance, flexible); satellites_param.setPathVectorSatellites(_pathvector_satellites); } @@ -250,34 +258,45 @@ void LPEFilletChamfer::updateAmount() void LPEFilletChamfer::updateChamferSteps() { + setSelected(_pathvector_satellites); _pathvector_satellites->updateSteps(chamfer_steps, apply_no_radius, apply_with_radius, only_selected); satellites_param.setPathVectorSatellites(_pathvector_satellites); } void LPEFilletChamfer::updateSatelliteType(SatelliteType satellitetype) { + setSelected(_pathvector_satellites); _pathvector_satellites->updateSatelliteType(satellitetype, apply_no_radius, apply_with_radius, only_selected); satellites_param.setPathVectorSatellites(_pathvector_satellites); } +void LPEFilletChamfer::setSelected(PathVectorSatellites *_pathvector_satellites){ + Geom::PathVector const pathv = _pathvector_satellites->getPathVector(); + Satellites satellites = _pathvector_satellites->getSatellites(); + for (size_t i = 0; i < satellites.size(); ++i) { + for (size_t j = 0; j < satellites[i].size(); ++j) { + Geom::Curve const &curve_in = pathv[i][j]; + if (only_selected && isNodePointSelected(curve_in.initialPoint()) ){ + satellites[i][j].setSelected(true); + } else { + satellites[i][j].setSelected(false); + } + } + } + _pathvector_satellites->setSatellites(satellites); +} + void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) { - SPLPEItem *splpeitem = const_cast(lpeItem); - SPShape *shape = dynamic_cast(splpeitem); - if (shape) { - SPCurve *c = shape->getCurve(); - SPPath *path = dynamic_cast(shape); - if (path) { - c = path->get_original_curve(); - } + if (sp_curve) { //fillet chamfer specific calls satellites_param.setUseDistance(use_knot_distance); satellites_param.setCurrentZoom(current_zoom); //mandatory call satellites_param.setEffectType(effectType()); - Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - //if are diferent sizes call to poinwise recalculate - //TODO: Update the satellite data in paths modified, Goal 0.93 + Geom::PathVector const pathv = pathv_to_linear_and_cubic_beziers(sp_curve->get_pathvector()); + //if are diferent sizes call to recalculate + //TODO: Update the satellite data in paths modified, Satellites satellites = satellites_param.data(); if (satellites.empty()) { doOnApply(lpeItem); @@ -305,16 +324,15 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } else { satellites_param.setHelperSize(helper_size); } - size_t index = 0; for (size_t i = 0; i < satellites.size(); ++i) { for (size_t j = 0; j < satellites[i].size(); ++j) { + Geom::Curve const &curve_in = pathv[i][j]; if (satellites[i][j].is_time != flexible) { satellites[i][j].is_time = flexible; double amount = satellites[i][j].amount; if (pathv[i].size() == j) { continue; } - Geom::Curve const &curve_in = pathv[i][j]; if (satellites[i][j].is_time) { double time = timeAtArcLength(amount, curve_in); satellites[i][j].amount = time; @@ -327,11 +345,9 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) satellites[i][j].has_mirror = mirror_knots; } satellites[i][j].hidden = hide_knots; - Geom::Curve const &curve_in = pathv[i][j]; if (only_selected && isNodePointSelected(curve_in.initialPoint()) ){ - selected_nodes_index.push_back(index); + satellites[i][j].setSelected(true); } - index ++; } } if (!_pathvector_satellites) { @@ -339,10 +355,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } _pathvector_satellites->setPathVector(pathv); _pathvector_satellites->setSatellites(satellites); - if (only_selected) { - _pathvector_satellites->setSelected(selected_nodes_index); - } - satellites_param.setPathVectorSatellites(_pathvector_satellites); + satellites_param.setPathVectorSatellites(_pathvector_satellites, false); refreshKnots(); } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); @@ -358,6 +371,7 @@ LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector< void LPEFilletChamfer::addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point, size_t steps) { + setSelected(_pathvector_satellites); double path_subdivision = 1.0 / steps; for (size_t i = 1; i < steps; i++) { Geom::Point chamfer_step = path_chamfer.pointAt(path_subdivision * i); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 2cee04a1e..7f5dd7d4c 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -40,7 +40,8 @@ public: void addChamferSteps(Geom::Path &tmp_path, Geom::Path path_chamfer, Geom::Point end_arc_point, size_t steps); void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector &hp_vec); void updateSatelliteType(SatelliteType satellitetype); - //void convertUnit(); + void setSelected(PathVectorSatellites *_pathvector_satellites); + //void convertUnit(); void updateChamferSteps(); void updateAmount(); void refreshKnots(); diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index c7bc7f026..7626317a1 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -39,6 +39,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label, _last_pathvector_satellites = NULL; } + void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) @@ -48,10 +49,14 @@ void SatellitesArrayParam::set_oncanvas_looks(SPKnotShapeType shape, _knot_color = color; } -void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites) +void SatellitesArrayParam::setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites, bool write) { _last_pathvector_satellites = pathVectorSatellites; - param_set_and_write_new_value(_last_pathvector_satellites->getSatellites()); + if (write) { + param_set_and_write_new_value(_last_pathvector_satellites->getSatellites()); + } else { + param_setValue(_last_pathvector_satellites->getSatellites()); + } } void SatellitesArrayParam::setUseDistance(bool use_knot_distance) @@ -226,6 +231,9 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item, bool mirror) { + if (!_last_pathvector_satellites) { + return; + } Geom::PathVector pathv = _last_pathvector_satellites->getPathVector(); size_t index = 0; for (size_t i = 0; i < _vector.size(); ++i) { @@ -442,7 +450,6 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { _pparam->_vector[path_index][curve_index].amount = 0.0; - _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); } else { using namespace Geom; @@ -462,7 +469,6 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) break; } _pparam->_vector[path_index][curve_index].satellite_type = type; - _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); const gchar *tip; if (type == CHAMFER) { @@ -555,7 +561,6 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite) satellite.amount = amount; _pparam->_vector[path_index][curve_index] = satellite; this->parent_holder->knot_ungrabbed_handler(this->knot, 0); - _pparam->param_set_and_write_new_value(_pparam->_vector); SPLPEItem *splpeitem = dynamic_cast(item); if (splpeitem) { sp_lpe_item_update_patheffect(splpeitem, false, false); diff --git a/src/live_effects/parameter/satellitesarray.h b/src/live_effects/parameter/satellitesarray.h index edaf2f08d..5ae372ac2 100644 --- a/src/live_effects/parameter/satellitesarray.h +++ b/src/live_effects/parameter/satellitesarray.h @@ -55,7 +55,7 @@ public: void setCurrentZoom(double current_zoom); void setGlobalKnotHide(bool global_knot_hide); void setEffectType(EffectType et); - void setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites); + void setPathVectorSatellites(PathVectorSatellites *pathVectorSatellites, bool write = true); void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color); friend class FilletChamferKnotHolderEntity; -- cgit v1.2.3