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 2a3581c9a5e6d18b3cd0ea2fe523063a116af8f8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 2 May 2016 09:47:14 +0200 Subject: Working on clip erase basic work done but broken (bzr r14865.1.1) --- src/sp-lpe-item.cpp | 36 ++++++++------ src/ui/tools/eraser-tool.cpp | 109 +++++++++++++++++++++++++++++++++++------ src/widgets/eraser-toolbar.cpp | 30 +++++++----- 3 files changed, 134 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index fdc2949d5..5753e9307 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -349,10 +349,10 @@ sp_lpe_item_create_original_path_recursive(SPLPEItem *lpeitem) { sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(mask->firstChild())); } - SPClipPath * clipPath = lpeitem->clip_ref->getObject(); - if(clipPath) + SPClipPath * clip_path = lpeitem->clip_ref->getObject(); + if(clip_path) { - sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild())); + sp_lpe_item_create_original_path_recursive(SP_LPE_ITEM(clip_path->firstChild())); } if (SP_IS_GROUP(lpeitem)) { std::vector item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); @@ -383,10 +383,10 @@ sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem) { sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(mask->firstChild())); } - SPClipPath * clipPath = lpeitem->clip_ref->getObject(); - if(clipPath) + SPClipPath * clip_path = lpeitem->clip_ref->getObject(); + if(clip_path) { - sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild())); + sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(clip_path->firstChild())); } } std::vector item_list = sp_item_group_item_list(SP_GROUP(lpeitem)); @@ -405,10 +405,10 @@ sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem) { sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(mask->firstChild())); } - SPClipPath * clipPath = lpeitem->clip_ref->getObject(); - if(clipPath) + SPClipPath * clip_path = lpeitem->clip_ref->getObject(); + if(clip_path) { - sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(clipPath->firstChild())); + sp_lpe_item_cleanup_original_path_recursive(SP_LPE_ITEM(clip_path->firstChild())); } repr->setAttribute("d", repr->attribute("inkscape:original-d")); repr->setAttribute("inkscape:original-d", NULL); @@ -640,10 +640,13 @@ bool SPLPEItem::hasPathEffectRecursive() const void SPLPEItem::apply_to_clippath(SPItem *item) { - SPClipPath *clipPath = item->clip_ref->getObject(); - if(clipPath) { - SPObject * clip_data = clipPath->firstChild(); - apply_to_clip_or_mask(SP_ITEM(clip_data), item); + SPClipPath *clip_path = item->clip_ref->getObject(); + if(clip_path) { + std::vector clip_path_list = clip_path->childList(true); + for ( std::vector::const_iterator iter=clip_path_list.begin();iter!=clip_path_list.end();++iter) { + SPObject * clip_data = *iter; + apply_to_clip_or_mask(SP_ITEM(clip_data), item); + } } if(SP_IS_GROUP(item)){ std::vector item_list = sp_item_group_item_list(SP_GROUP(item)); @@ -659,8 +662,11 @@ SPLPEItem::apply_to_mask(SPItem *item) { SPMask *mask = item->mask_ref->getObject(); if(mask) { - SPObject *mask_data = mask->firstChild(); - apply_to_clip_or_mask(SP_ITEM(mask_data), item); + std::vector mask_list = mask->childList(true); + for ( std::vector::const_iterator iter=mask_list.begin();iter!=mask_list.end();++iter) { + SPObject * mask_data = *iter; + apply_to_clip_or_mask(SP_ITEM(mask_data), item); + } } if(SP_IS_GROUP(item)){ std::vector item_list = sp_item_group_item_list(SP_GROUP(item)); diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 6b32b5901..38e599c05 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -58,6 +58,8 @@ #include "sp-item-group.h" #include "sp-shape.h" #include "sp-path.h" +#include "sp-clippath.h" +#include "sp-rect.h" #include "sp-text.h" #include "display/canvas-bpath.h" #include "display/canvas-arena.h" @@ -69,6 +71,7 @@ #include <2geom/math-utils.h> #include <2geom/pathvector.h> #include "path-chemistry.h" +#include "selection-chemistry.h" #include "display/curve.h" #include "ui/tools/eraser-tool.h" @@ -380,7 +383,7 @@ void EraserTool::cancel() { bool EraserTool::root_handler(GdkEvent* event) { gint ret = FALSE; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0; + gint eraser_mode = prefs->getInt("/tools/eraser/mode", 2); switch (event->type) { case GDK_BUTTON_PRESS: if (event->button.button == 1 && !this->space_panning) { @@ -400,7 +403,7 @@ bool EraserTool::root_handler(GdkEvent* event) { if (this->repr) { this->repr = NULL; } - if ( ! eraserMode ) { + if ( eraser_mode == 0 ) { Inkscape::Rubberband::get(desktop)->start(desktop, button_dt); Inkscape::Rubberband::get(desktop)->setMode(RUBBERBAND_MODE_TOUCHPATH); } @@ -448,7 +451,7 @@ bool EraserTool::root_handler(GdkEvent* event) { ret = TRUE; } - if ( !eraserMode ) { + if ( eraser_mode == 0 ) { this->accumulated->reset(); Inkscape::Rubberband::get(desktop)->move(motion_dt); } @@ -491,7 +494,7 @@ bool EraserTool::root_handler(GdkEvent* event) { ret = TRUE; } - if (!eraserMode && Inkscape::Rubberband::get(desktop)->is_started()) { + if (eraser_mode == 0 && Inkscape::Rubberband::get(desktop)->is_started()) { Inkscape::Rubberband::get(desktop)->stop(); } @@ -578,7 +581,7 @@ bool EraserTool::root_handler(GdkEvent* event) { break; case GDK_KEY_Escape: - if ( !eraserMode ) { + if ( eraser_mode == 0 ) { Inkscape::Rubberband::get(desktop)->stop(); } if (this->is_drawing) { @@ -640,7 +643,9 @@ void EraserTool::clear_current() { void EraserTool::set_to_accumulated() { bool workDone = false; - + SPDocument *document = this->desktop->doc(); +// bool has_undo_sensitive = DocumentUndo::getUndoSensitive(document); +// DocumentUndo::setUndoSensitive(document, false); if (!this->accumulated->is_empty()) { if (!this->repr) { /* Create object */ @@ -666,7 +671,7 @@ void EraserTool::set_to_accumulated() { bool wasSelection = false; Inkscape::Selection *selection = desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0; + gint eraser_mode = prefs->getInt("/tools/eraser/mode", 2); Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); SPItem* acid = SP_ITEM(desktop->doc()->getObjectByRepr(this->repr)); @@ -674,7 +679,7 @@ void EraserTool::set_to_accumulated() { std::vector remainingItems; std::vector toWorkOn; if (selection->isEmpty()) { - if ( eraserMode ) { + if ( eraser_mode == 1 || eraser_mode == 2) { toWorkOn = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *eraserBbox); } else { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); @@ -682,7 +687,7 @@ void EraserTool::set_to_accumulated() { } toWorkOn.erase(std::remove(toWorkOn.begin(), toWorkOn.end(), acid), toWorkOn.end()); } else { - if ( !eraserMode ) { + if ( eraser_mode == 0 ) { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); std::vector touched; touched = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints()); @@ -698,7 +703,7 @@ void EraserTool::set_to_accumulated() { } if ( !toWorkOn.empty() ) { - if ( eraserMode ) { + if ( eraser_mode == 1 ) { for (std::vector::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); ++i){ SPItem *item = *i; SPUse *use = dynamic_cast(item); @@ -708,7 +713,6 @@ void EraserTool::set_to_accumulated() { item->deleteObject(true); sp_object_unref(item); workDone = true; - workDone = true; } else if (SP_IS_GROUP(item) || use ) { /*Do nothing*/ } else { @@ -755,6 +759,81 @@ void EraserTool::set_to_accumulated() { } } } + } else if ( eraser_mode == 2 ) { + for (std::vector::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); ++i){ + selection->clear(); + SPItem *item = *i; + Geom::OptRect bbox = item->desktopVisualBounds(); + Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc(); + Inkscape::XML::Node *rect_repr = xml_doc->createElement("svg:rect"); + SPRect * rect = SP_RECT(this->desktop->currentLayer()->appendChildRepr(rect_repr)); + rect->updateRepr(); + rect->setPosition (bbox.min()[Geom::X], bbox.min()[Geom::Y], bbox.dimensions()[Geom::X], bbox.dimensions()[Geom::Y]); + rect->doWriteTransform(rect_repr, SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse() * this->desktop->dt2doc()); + Inkscape::GC::release(rect_repr); + + + Inkscape::XML::Node *rect_repr2 = xml_doc->createElement("svg:rect"); + SPRect * rect2 = SP_RECT(this->desktop->currentLayer()->appendChildRepr(rect_repr2)); + rect2->updateRepr(); + sp_desktop_apply_style_tool (desktop, rect_repr2, "/tools/shapes/rect", false); + rect2->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height()); + rect->doWriteTransform(rect_repr, SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse() * this->desktop->dt2doc()); + Inkscape::GC::release(rect_repr2); + + + Inkscape::XML::Node *rect_repr3 = xml_doc->createElement("svg:rect"); + SPRect * rect3 = SP_RECT(this->desktop->currentLayer()->appendChildRepr(rect_repr3)); + rect3->updateRepr(); + sp_desktop_apply_style_tool (desktop, rect_repr3, "/tools/shapes/rect", false); + rect3->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height()); + rect->doWriteTransform(rect_repr3, SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse() * this->desktop->doc2dt()); + Inkscape::GC::release(rect_repr3); + + + + + + Inkscape::XML::Node* dup = this->repr->duplicate(xml_doc); + this->repr->parent()->appendChild(dup); + Inkscape::GC::release(dup); // parent takes over + selection->set(dup); + sp_selected_path_union_skip_undo(selection, this->desktop); + sp_selection_raise_to_top(selection, this->desktop); + if (bbox && bbox->intersects(*eraserBbox)) { + SPClipPath *clip_path = item->clip_ref->getObject(); + if (clip_path) { + SPObject *clip_data = clip_path->firstChild(); + Inkscape::XML::Node *dup_clip = clip_data->getRepr()->duplicate(xml_doc); + if (dup_clip) { + this->repr->parent()->appendChild(dup_clip); + sp_object_ref(clip_data, 0); + clip_data->deleteObject(true); + sp_object_unref(clip_data); + sp_selection_raise_to_top(selection, this->desktop); + selection->add(dup_clip); + } + } else { + selection->add(rect); + } + sp_selected_path_diff_skip_undo(selection, this->desktop); + sp_selection_raise_to_top(selection, this->desktop); + selection->add(item); + sp_selection_set_mask(this->desktop, true, false); + } else { + SPItem *erase_clip = selection->singleItem(); + if (erase_clip) { + sp_object_ref(erase_clip, 0); + erase_clip->deleteObject(true); + sp_object_unref(erase_clip); + } + } + workDone = true; + } + selection->clear(); + if (wasSelection) { + selection->setList(toWorkOn); + } } else { for (std::vector ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();++i) { sp_object_ref( *i, 0 ); @@ -768,7 +847,7 @@ void EraserTool::set_to_accumulated() { } } - if ( !eraserMode ) { + if ( eraser_mode == 0 ) { //sp_selection_delete(desktop); remainingItems.clear(); } @@ -792,7 +871,7 @@ void EraserTool::set_to_accumulated() { } } - +// DocumentUndo::setUndoSensitive(document, has_undo_sensitive); if ( workDone ) { DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_ERASER, _("Draw eraser stroke")); } else { @@ -987,7 +1066,7 @@ void EraserTool::fit_and_split(bool release) { g_print("[%d]Yup\n", this->npoints); #endif if (!release) { - gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0; + gint eraser_mode = prefs->getInt("/tools/eraser/mode",2); g_assert(!this->currentcurve->is_empty()); SPCanvasItem *cbp = sp_canvas_item_new(desktop->getSketch(), SP_TYPE_CANVAS_BPATH, NULL); @@ -1009,7 +1088,7 @@ void EraserTool::fit_and_split(bool release) { this->segments = g_slist_prepend(this->segments, cbp); - if ( !eraserMode ) { + if ( eraser_mode == 0 ) { sp_canvas_item_hide(cbp); sp_canvas_item_hide(this->currentshape); } diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp index 45989936f..5b883905b 100644 --- a/src/widgets/eraser-toolbar.cpp +++ b/src/widgets/eraser-toolbar.cpp @@ -67,15 +67,15 @@ static void sp_erc_mass_value_changed( GtkAdjustment *adj, GObject* tbl ) static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) { SPDesktop *desktop = static_cast(g_object_get_data( tbl, "desktop" )); - bool eraserMode = ege_select_one_action_get_active( act ) != 0; + guint eraser_mode = ege_select_one_action_get_active( act ); if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool( "/tools/eraser/mode", eraserMode ); + prefs->setInt( "/tools/eraser/mode", eraser_mode ); } GtkAction *split = GTK_ACTION( g_object_get_data(tbl, "split") ); GtkAction *mass = GTK_ACTION( g_object_get_data(tbl, "mass") ); GtkAction *width = GTK_ACTION( g_object_get_data(tbl, "width") ); - if(eraserMode == TRUE){ + if(eraser_mode != 0){ gtk_action_set_visible( split, TRUE ); gtk_action_set_visible( mass, TRUE ); gtk_action_set_visible( width, TRUE ); @@ -90,7 +90,7 @@ static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); /* - if ( eraserMode != 0 ) { + if ( eraser_mode != 0 ) { } else { } */ @@ -111,7 +111,7 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb { Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gint eraserMode = FALSE; + gint eraser_mode = FALSE; { GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING ); GtkTreeIter iter; @@ -125,10 +125,17 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb gtk_list_store_append( model, &iter ); gtk_list_store_set( model, &iter, 0, _("Cut"), - 1, _("Cut out from objects"), + 1, _("Cut out from paths and shapes"), 2, INKSCAPE_ICON("path-difference"), -1 ); + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("Clip"), + 1, _("Clip from objects"), + 2, INKSCAPE_ICON("path-intersection"), + -1 ); + EgeSelectOneAction* act = ege_select_one_action_new( "EraserModeAction", (""), (""), NULL, GTK_TREE_MODEL(model) ); g_object_set( act, "short_label", _("Mode:"), NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); @@ -137,12 +144,13 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb ege_select_one_action_set_appearance( act, "full" ); ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE ); g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL ); - ege_select_one_action_set_icon_column( act, 2 ); - ege_select_one_action_set_tooltip_column( act, 1 ); + ege_select_one_action_set_icon_column( act, 2); + ege_select_one_action_set_icon_size( act, secondarySize ); + ege_select_one_action_set_tooltip_column( act, 1); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - eraserMode = prefs->getBool("/tools/eraser/mode") ? TRUE : FALSE; - ege_select_one_action_set_active( act, eraserMode ); + eraser_mode = prefs->getInt("/tools/eraser/mode", 2); + ege_select_one_action_set_active( act, eraser_mode ); g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_erasertb_mode_changed), holder ); } @@ -195,7 +203,7 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb GtkAction *split = GTK_ACTION( g_object_get_data(holder, "split") ); GtkAction *mass = GTK_ACTION( g_object_get_data(holder, "mass") ); GtkAction *width = GTK_ACTION( g_object_get_data(holder, "width") ); - if(eraserMode == TRUE){ + if (eraser_mode != 0) { gtk_action_set_visible( split, TRUE ); gtk_action_set_visible( mass, TRUE ); gtk_action_set_visible( width, TRUE ); -- cgit v1.2.3 From c425407979c2eca1a6fe6858923619de18c8d058 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 6 May 2016 22:56:57 +0200 Subject: Finishing eraser tool. TODO undo work (bzr r14865.1.2) --- src/document-undo.cpp | 21 +++++++---- src/document-undo.h | 4 +- src/ui/tools/eraser-tool.cpp | 90 ++++++++++++++++++++++---------------------- 3 files changed, 61 insertions(+), 54 deletions(-) (limited to 'src') diff --git a/src/document-undo.cpp b/src/document-undo.cpp index eb0ac7707..f6bcf3ab2 100644 --- a/src/document-undo.cpp +++ b/src/document-undo.cpp @@ -328,28 +328,35 @@ gboolean Inkscape::DocumentUndo::redo(SPDocument *doc) return ret; } -void Inkscape::DocumentUndo::clearUndo(SPDocument *doc) +void Inkscape::DocumentUndo::clearUndo(SPDocument *doc, size_t limit) { if (! doc->priv->undo.empty()) doc->priv->undoStackObservers.notifyClearUndoEvent(); - while (! doc->priv->undo.empty()) { + if (limit == 0) { + limit = doc->priv->undo.size(); + } + while (! doc->priv->undo.empty() && limit > 0) { Inkscape::Event *e = doc->priv->undo.back(); doc->priv->undo.pop_back(); delete e; doc->priv->history_size--; + limit--; } } -void Inkscape::DocumentUndo::clearRedo(SPDocument *doc) +void Inkscape::DocumentUndo::clearRedo(SPDocument *doc, size_t limit) { - if (!doc->priv->redo.empty()) - doc->priv->undoStackObservers.notifyClearRedoEvent(); - - while (! doc->priv->redo.empty()) { + if (!doc->priv->redo.empty()) + doc->priv->undoStackObservers.notifyClearRedoEvent(); + if (limit == 0) { + limit = doc->priv->undo.size(); + } + while (! doc->priv->redo.empty() && limit > 0) { Inkscape::Event *e = doc->priv->redo.back(); doc->priv->redo.pop_back(); delete e; doc->priv->history_size--; + limit--; } } diff --git a/src/document-undo.h b/src/document-undo.h index 85b44d562..559036458 100644 --- a/src/document-undo.h +++ b/src/document-undo.h @@ -33,9 +33,9 @@ public: static bool getUndoSensitive(SPDocument const *document); - static void clearUndo(SPDocument *document); + static void clearUndo(SPDocument *document, size_t limit = 0); - static void clearRedo(SPDocument *document); + static void clearRedo(SPDocument *document, size_t limit = 0); static void done(SPDocument *document, unsigned int event_type, Glib::ustring const &event_description); diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 38e599c05..f1c7306b4 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -644,8 +644,6 @@ void EraserTool::clear_current() { void EraserTool::set_to_accumulated() { bool workDone = false; SPDocument *document = this->desktop->doc(); -// bool has_undo_sensitive = DocumentUndo::getUndoSensitive(document); -// DocumentUndo::setUndoSensitive(document, false); if (!this->accumulated->is_empty()) { if (!this->repr) { /* Create object */ @@ -657,11 +655,11 @@ void EraserTool::set_to_accumulated() { this->repr = repr; } - SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(this->repr)); + SPItem *item_repr = SP_ITEM(desktop->currentLayer()->appendChildRepr(this->repr)); Inkscape::GC::release(this->repr); - item->updateRepr(); + item_repr->updateRepr(); Geom::PathVector pathv = this->accumulated->get_pathvector() * desktop->dt2doc(); - pathv *= item->i2doc_affine().inverse(); + pathv *= item_repr->i2doc_affine().inverse(); gchar *str = sp_svg_write_path(pathv); g_assert( str != NULL ); this->repr->setAttribute("d", str); @@ -760,66 +758,68 @@ void EraserTool::set_to_accumulated() { } } } else if ( eraser_mode == 2 ) { + remainingItems.clear(); for (std::vector::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); ++i){ selection->clear(); + size_t n_undo = 0; SPItem *item = *i; Geom::OptRect bbox = item->desktopVisualBounds(); Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc(); Inkscape::XML::Node *rect_repr = xml_doc->createElement("svg:rect"); + sp_desktop_apply_style_tool (desktop, rect_repr, "/tools/eraser", false); SPRect * rect = SP_RECT(this->desktop->currentLayer()->appendChildRepr(rect_repr)); - rect->updateRepr(); - rect->setPosition (bbox.min()[Geom::X], bbox.min()[Geom::Y], bbox.dimensions()[Geom::X], bbox.dimensions()[Geom::Y]); - rect->doWriteTransform(rect_repr, SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse() * this->desktop->dt2doc()); Inkscape::GC::release(rect_repr); - - Inkscape::XML::Node *rect_repr2 = xml_doc->createElement("svg:rect"); - SPRect * rect2 = SP_RECT(this->desktop->currentLayer()->appendChildRepr(rect_repr2)); - rect2->updateRepr(); - sp_desktop_apply_style_tool (desktop, rect_repr2, "/tools/shapes/rect", false); - rect2->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height()); - rect->doWriteTransform(rect_repr, SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse() * this->desktop->dt2doc()); - Inkscape::GC::release(rect_repr2); - - - Inkscape::XML::Node *rect_repr3 = xml_doc->createElement("svg:rect"); - SPRect * rect3 = SP_RECT(this->desktop->currentLayer()->appendChildRepr(rect_repr3)); - rect3->updateRepr(); - sp_desktop_apply_style_tool (desktop, rect_repr3, "/tools/shapes/rect", false); - rect3->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height()); - rect->doWriteTransform(rect_repr3, SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse() * this->desktop->doc2dt()); - Inkscape::GC::release(rect_repr3); - - - - - + rect->updateRepr(); + rect->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height()); + rect->transform = SP_ITEM(desktop->currentLayer())->i2dt_affine().inverse(); + Inkscape::XML::Node* dup = this->repr->duplicate(xml_doc); this->repr->parent()->appendChild(dup); Inkscape::GC::release(dup); // parent takes over selection->set(dup); sp_selected_path_union_skip_undo(selection, this->desktop); sp_selection_raise_to_top(selection, this->desktop); + n_undo++; if (bbox && bbox->intersects(*eraserBbox)) { SPClipPath *clip_path = item->clip_ref->getObject(); if (clip_path) { - SPObject *clip_data = clip_path->firstChild(); - Inkscape::XML::Node *dup_clip = clip_data->getRepr()->duplicate(xml_doc); - if (dup_clip) { - this->repr->parent()->appendChild(dup_clip); - sp_object_ref(clip_data, 0); - clip_data->deleteObject(true); - sp_object_unref(clip_data); - sp_selection_raise_to_top(selection, this->desktop); - selection->add(dup_clip); + SPPath *clip_data = SP_PATH(clip_path->firstChild()); + if (clip_data) { + Inkscape::XML::Node *dup_clip = SP_OBJECT(clip_data)->getRepr()->duplicate(xml_doc); + if (dup_clip) { + SPItem * dup_clip_obj = SP_ITEM(item_repr->parent->appendChildRepr(dup_clip)); + if (dup_clip_obj) { + dup_clip_obj->doWriteTransform(dup_clip, item->transform); + sp_object_ref(clip_data, 0); + clip_data->deleteObject(true); + sp_object_unref(clip_data); + sp_object_ref(clip_path, 0); + clip_path->deleteObject(true); + sp_object_unref(clip_path); + sp_object_ref(rect, 0); + rect->deleteObject(true); + sp_object_unref(rect); + sp_selection_raise_to_top(selection, this->desktop); + n_undo++; + selection->add(dup_clip); + sp_selected_path_diff_skip_undo(selection, this->desktop); + n_undo++; + SPItem * clip = SP_ITEM(selection->itemList()[0]); + } + } } } else { selection->add(rect); + sp_selected_path_diff_skip_undo(selection, this->desktop); + n_undo++; } - sp_selected_path_diff_skip_undo(selection, this->desktop); sp_selection_raise_to_top(selection, this->desktop); + n_undo++; selection->add(item); sp_selection_set_mask(this->desktop, true, false); + n_undo++; + DocumentUndo::clearUndo(document, n_undo); } else { SPItem *erase_clip = selection->singleItem(); if (erase_clip) { @@ -829,11 +829,12 @@ void EraserTool::set_to_accumulated() { } } workDone = true; + selection->clear(); + if (wasSelection) { + remainingItems.push_back(item); + } } - selection->clear(); - if (wasSelection) { - selection->setList(toWorkOn); - } + } else { for (std::vector ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();++i) { sp_object_ref( *i, 0 ); @@ -871,7 +872,6 @@ void EraserTool::set_to_accumulated() { } } -// DocumentUndo::setUndoSensitive(document, has_undo_sensitive); if ( workDone ) { DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_ERASER, _("Draw eraser stroke")); } else { -- cgit v1.2.3 From 72610e6bbd79b3a3e9a980980ebc2f533ea8056d Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 7 May 2016 01:37:50 +0200 Subject: working on undo (bzr r14865.1.4) --- src/document-undo.cpp | 23 ++++++++--------------- src/document-undo.h | 4 ++-- src/ui/tools/eraser-tool.cpp | 21 ++++++--------------- 3 files changed, 16 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/document-undo.cpp b/src/document-undo.cpp index f6bcf3ab2..7e6fe5df1 100644 --- a/src/document-undo.cpp +++ b/src/document-undo.cpp @@ -141,7 +141,7 @@ void Inkscape::DocumentUndo::maybeDone(SPDocument *doc, const gchar *key, const { g_assert (doc != NULL); g_assert (doc->priv != NULL); - g_assert (doc->priv->sensitive); + //g_assert (doc->priv->sensitive); if ( key && !*key ) { g_warning("Blank undo key specified."); } @@ -328,35 +328,28 @@ gboolean Inkscape::DocumentUndo::redo(SPDocument *doc) return ret; } -void Inkscape::DocumentUndo::clearUndo(SPDocument *doc, size_t limit) +void Inkscape::DocumentUndo::clearUndo(SPDocument *doc) { if (! doc->priv->undo.empty()) doc->priv->undoStackObservers.notifyClearUndoEvent(); - if (limit == 0) { - limit = doc->priv->undo.size(); - } - while (! doc->priv->undo.empty() && limit > 0) { + while (! doc->priv->undo.empty()) { Inkscape::Event *e = doc->priv->undo.back(); doc->priv->undo.pop_back(); delete e; doc->priv->history_size--; - limit--; } } -void Inkscape::DocumentUndo::clearRedo(SPDocument *doc, size_t limit) +void Inkscape::DocumentUndo::clearRedo(SPDocument *doc) { - if (!doc->priv->redo.empty()) - doc->priv->undoStackObservers.notifyClearRedoEvent(); - if (limit == 0) { - limit = doc->priv->undo.size(); - } - while (! doc->priv->redo.empty() && limit > 0) { + if (!doc->priv->redo.empty()) + doc->priv->undoStackObservers.notifyClearRedoEvent(); + + while (! doc->priv->redo.empty()) { Inkscape::Event *e = doc->priv->redo.back(); doc->priv->redo.pop_back(); delete e; doc->priv->history_size--; - limit--; } } diff --git a/src/document-undo.h b/src/document-undo.h index 559036458..85b44d562 100644 --- a/src/document-undo.h +++ b/src/document-undo.h @@ -33,9 +33,9 @@ public: static bool getUndoSensitive(SPDocument const *document); - static void clearUndo(SPDocument *document, size_t limit = 0); + static void clearUndo(SPDocument *document); - static void clearRedo(SPDocument *document, size_t limit = 0); + static void clearRedo(SPDocument *document); static void done(SPDocument *document, unsigned int event_type, Glib::ustring const &event_description); diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index f1c7306b4..b62f68a5f 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -721,7 +721,7 @@ void EraserTool::set_to_accumulated() { Inkscape::GC::release(dup); // parent takes over selection->set(dup); if (!this->nowidth) { - sp_selected_path_union_skip_undo(selection, desktop); + sp_selected_path_union(selection, desktop); } selection->add(item); if(item->style->fill_rule.value == SP_WIND_RULE_EVENODD){ @@ -732,9 +732,9 @@ void EraserTool::set_to_accumulated() { css = 0; } if (this->nowidth) { - sp_selected_path_cut_skip_undo(selection, desktop); + sp_selected_path_cut(selection, desktop); } else { - sp_selected_path_diff_skip_undo(selection, desktop); + sp_selected_path_diff(selection, desktop); } workDone = true; // TODO set this only if something was cut. bool break_apart = prefs->getBool("/tools/eraser/break_apart", false); @@ -761,7 +761,6 @@ void EraserTool::set_to_accumulated() { remainingItems.clear(); for (std::vector::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); ++i){ selection->clear(); - size_t n_undo = 0; SPItem *item = *i; Geom::OptRect bbox = item->desktopVisualBounds(); Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc(); @@ -778,9 +777,8 @@ void EraserTool::set_to_accumulated() { this->repr->parent()->appendChild(dup); Inkscape::GC::release(dup); // parent takes over selection->set(dup); - sp_selected_path_union_skip_undo(selection, this->desktop); + sp_selected_path_union(selection, this->desktop); sp_selection_raise_to_top(selection, this->desktop); - n_undo++; if (bbox && bbox->intersects(*eraserBbox)) { SPClipPath *clip_path = item->clip_ref->getObject(); if (clip_path) { @@ -801,25 +799,19 @@ void EraserTool::set_to_accumulated() { rect->deleteObject(true); sp_object_unref(rect); sp_selection_raise_to_top(selection, this->desktop); - n_undo++; selection->add(dup_clip); - sp_selected_path_diff_skip_undo(selection, this->desktop); - n_undo++; + sp_selected_path_diff(selection, this->desktop); SPItem * clip = SP_ITEM(selection->itemList()[0]); } } } } else { selection->add(rect); - sp_selected_path_diff_skip_undo(selection, this->desktop); - n_undo++; + sp_selected_path_diff(selection, this->desktop); } sp_selection_raise_to_top(selection, this->desktop); - n_undo++; selection->add(item); sp_selection_set_mask(this->desktop, true, false); - n_undo++; - DocumentUndo::clearUndo(document, n_undo); } else { SPItem *erase_clip = selection->singleItem(); if (erase_clip) { @@ -871,7 +863,6 @@ void EraserTool::set_to_accumulated() { this->repr = 0; } } - if ( workDone ) { DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_ERASER, _("Draw eraser stroke")); } else { -- 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 2d2718e48ee56f975342f0329b98f892f118d85e Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 22 May 2016 00:03:52 +0200 Subject: Fixing undo thing (bzr r14865.1.5) --- src/document-private.h | 57 +++++---- src/document-undo.cpp | 298 ++++++++++++++++++++++++------------------- src/document-undo.h | 4 + src/document.cpp | 1 + src/selection-chemistry.cpp | 31 +++-- src/selection-chemistry.h | 6 +- src/ui/tools/eraser-tool.cpp | 29 ++++- 7 files changed, 243 insertions(+), 183 deletions(-) (limited to 'src') diff --git a/src/document-private.h b/src/document-private.h index eaed0020e..6ec535b87 100644 --- a/src/document-private.h +++ b/src/document-private.h @@ -37,43 +37,44 @@ class Event; } struct SPDocumentPrivate { - typedef std::map IDChangedSignalMap; - typedef std::map ResourcesChangedSignalMap; + typedef std::map IDChangedSignalMap; + typedef std::map ResourcesChangedSignalMap; - std::map iddef; - std::map reprdef; + std::map iddef; + std::map reprdef; - unsigned long serial; + unsigned long serial; - /** Dictionary of signals for id changes */ - IDChangedSignalMap id_changed_signals; + /** Dictionary of signals for id changes */ + IDChangedSignalMap id_changed_signals; - /* Resources */ - std::map > resources; - ResourcesChangedSignalMap resources_changed_signals; + /* Resources */ + std::map > resources; + ResourcesChangedSignalMap resources_changed_signals; - sigc::signal destroySignal; - SPDocument::ModifiedSignal modified_signal; - SPDocument::URISetSignal uri_set_signal; - SPDocument::ResizedSignal resized_signal; - SPDocument::ReconstructionStart _reconstruction_start_signal; - SPDocument::ReconstructionFinish _reconstruction_finish_signal; - SPDocument::CommitSignal commit_signal; + sigc::signal destroySignal; + SPDocument::ModifiedSignal modified_signal; + SPDocument::URISetSignal uri_set_signal; + SPDocument::ResizedSignal resized_signal; + SPDocument::ReconstructionStart _reconstruction_start_signal; + SPDocument::ReconstructionFinish _reconstruction_finish_signal; + SPDocument::CommitSignal commit_signal; - /* Undo/Redo state */ - bool sensitive; /* If we save actions to undo stack */ - Inkscape::XML::Event * partial; /* partial undo log when interrupted */ - int history_size; - std::vector undo; /* Undo stack of reprs */ - std::vector redo; /* Redo stack of reprs */ + /* Undo/Redo state */ + bool sensitive; /* If we save actions to undo stack */ + bool join_undo; /* If we group actions to one undo stack */ + Inkscape::XML::Event * partial; /* partial undo log when interrupted */ + int history_size; + std::vector undo; /* Undo stack of reprs */ + std::vector redo; /* Redo stack of reprs */ - /* Undo listener */ - Inkscape::CompositeUndoStackObserver undoStackObservers; + /* Undo listener */ + Inkscape::CompositeUndoStackObserver undoStackObservers; - // XXX only for testing! - Inkscape::ConsoleOutputUndoObserver console_output_undo_observer; + // XXX only for testing! + Inkscape::ConsoleOutputUndoObserver console_output_undo_observer; - bool seeking; + bool seeking; sigc::connection selChangeConnection; sigc::connection desktopActivatedConnection; }; diff --git a/src/document-undo.cpp b/src/document-undo.cpp index 7e6fe5df1..1707fb6fa 100644 --- a/src/document-undo.cpp +++ b/src/document-undo.cpp @@ -62,22 +62,22 @@ void Inkscape::DocumentUndo::setUndoSensitive(SPDocument *doc, bool sensitive) { - g_assert (doc != NULL); - g_assert (doc->priv != NULL); - - if ( sensitive == doc->priv->sensitive ) - return; - - if (sensitive) { - sp_repr_begin_transaction (doc->rdoc); - } else { - doc->priv->partial = sp_repr_coalesce_log ( - doc->priv->partial, - sp_repr_commit_undoable (doc->rdoc) - ); - } - - doc->priv->sensitive = sensitive; + g_assert (doc != NULL); + g_assert (doc->priv != NULL); + + if ( sensitive == doc->priv->sensitive ) + return; + + if (sensitive) { + sp_repr_begin_transaction (doc->rdoc); + } else { + doc->priv->partial = sp_repr_coalesce_log ( + doc->priv->partial, + sp_repr_commit_undoable (doc->rdoc) + ); + } + + doc->priv->sensitive = sensitive; } /*TODO: Throughout the inkscape code tree set/get_undo_sensitive are used for @@ -88,15 +88,49 @@ void Inkscape::DocumentUndo::setUndoSensitive(SPDocument *doc, bool sensitive) */ bool Inkscape::DocumentUndo::getUndoSensitive(SPDocument const *document) { - g_assert(document != NULL); - g_assert(document->priv != NULL); + g_assert(document != NULL); + g_assert(document->priv != NULL); + + return document->priv->sensitive; +} + +void Inkscape::DocumentUndo::setUndoJoined(SPDocument *doc, bool join_undo) +{ + g_assert (doc != NULL); + g_assert (doc->priv != NULL); + if (join_undo) { + doc->collectOrphans(); + doc->ensureUpToDate(); + DocumentUndo::clearRedo(doc); + Inkscape::XML::Event *log = sp_repr_coalesce_log (doc->priv->partial, sp_repr_commit_undoable (doc->rdoc)); + doc->priv->partial = NULL; + if (!log) { + sp_repr_begin_transaction (doc->rdoc); + doc->priv->join_undo = join_undo; + return; + } + doc->virgin = FALSE; + doc->setModifiedSinceSave(); + sp_repr_begin_transaction (doc->rdoc); + doc->priv->commit_signal.emit(); + } + doc->priv->join_undo = join_undo; +} - return document->priv->sensitive; +bool Inkscape::DocumentUndo::getUndoJoined(SPDocument *doc) +{ + g_assert (doc != NULL); + g_assert (doc->priv != NULL); + return doc->priv->join_undo; } void Inkscape::DocumentUndo::done(SPDocument *doc, const unsigned int event_type, Glib::ustring const &event_description) { - maybeDone(doc, NULL, event_type, event_description); + if (!getUndoJoined(doc)) { + maybeDone(doc, NULL, event_type, event_description); + } else { + sp_repr_commit_undoable (doc->rdoc); + } } void Inkscape::DocumentUndo::resetKey( SPDocument *doc ) @@ -139,82 +173,81 @@ public: void Inkscape::DocumentUndo::maybeDone(SPDocument *doc, const gchar *key, const unsigned int event_type, Glib::ustring const &event_description) { - g_assert (doc != NULL); - g_assert (doc->priv != NULL); - //g_assert (doc->priv->sensitive); - if ( key && !*key ) { - g_warning("Blank undo key specified."); - } + g_assert (doc != NULL); + g_assert (doc->priv != NULL); + g_assert (doc->priv->sensitive); + if ( key && !*key ) { + g_warning("Blank undo key specified."); + } - Inkscape::Debug::EventTracker tracker(doc, key, event_type); + Inkscape::Debug::EventTracker tracker(doc, key, event_type); - doc->collectOrphans(); + doc->collectOrphans(); - doc->ensureUpToDate(); + doc->ensureUpToDate(); - DocumentUndo::clearRedo(doc); + DocumentUndo::clearRedo(doc); - Inkscape::XML::Event *log = sp_repr_coalesce_log (doc->priv->partial, sp_repr_commit_undoable (doc->rdoc)); - doc->priv->partial = NULL; + Inkscape::XML::Event *log = sp_repr_coalesce_log (doc->priv->partial, sp_repr_commit_undoable (doc->rdoc)); + doc->priv->partial = NULL; - if (!log) { - sp_repr_begin_transaction (doc->rdoc); - return; - } + if (!log) { + sp_repr_begin_transaction (doc->rdoc); + return; + } - if (key && !doc->actionkey.empty() && (doc->actionkey == key) && !doc->priv->undo.empty()) { - (doc->priv->undo.back())->event = - sp_repr_coalesce_log ((doc->priv->undo.back())->event, log); - } else { - Inkscape::Event *event = new Inkscape::Event(log, event_type, event_description); - doc->priv->undo.push_back(event); - doc->priv->history_size++; - doc->priv->undoStackObservers.notifyUndoCommitEvent(event); - } + if (key && !doc->actionkey.empty() && (doc->actionkey == key) && !doc->priv->undo.empty()) { + (doc->priv->undo.back())->event = sp_repr_coalesce_log ((doc->priv->undo.back())->event, log); + } else { + Inkscape::Event *event = new Inkscape::Event(log, event_type, event_description); + doc->priv->undo.push_back(event); + doc->priv->history_size++; + doc->priv->undoStackObservers.notifyUndoCommitEvent(event); + } - if ( key ) { - doc->actionkey = key; - } else { - doc->actionkey.clear(); - } + if ( key ) { + doc->actionkey = key; + } else { + doc->actionkey.clear(); + } - doc->virgin = FALSE; - doc->setModifiedSinceSave(); + doc->virgin = FALSE; + doc->setModifiedSinceSave(); - sp_repr_begin_transaction (doc->rdoc); + sp_repr_begin_transaction (doc->rdoc); - doc->priv->commit_signal.emit(); + doc->priv->commit_signal.emit(); } void Inkscape::DocumentUndo::cancel(SPDocument *doc) { - g_assert (doc != NULL); - g_assert (doc->priv != NULL); - g_assert (doc->priv->sensitive); + g_assert (doc != NULL); + g_assert (doc->priv != NULL); + g_assert (doc->priv->sensitive); - sp_repr_rollback (doc->rdoc); + sp_repr_rollback (doc->rdoc); - if (doc->priv->partial) { - sp_repr_undo_log (doc->priv->partial); - sp_repr_free_log (doc->priv->partial); - doc->priv->partial = NULL; - } + if (doc->priv->partial) { + sp_repr_undo_log (doc->priv->partial); + sp_repr_free_log (doc->priv->partial); + doc->priv->partial = NULL; + } - sp_repr_begin_transaction (doc->rdoc); + sp_repr_begin_transaction (doc->rdoc); } static void finish_incomplete_transaction(SPDocument &doc) { - SPDocumentPrivate &priv=*doc.priv; - Inkscape::XML::Event *log=sp_repr_commit_undoable(doc.rdoc); - if (log || priv.partial) { - g_warning ("Incomplete undo transaction:"); - priv.partial = sp_repr_coalesce_log(priv.partial, log); - sp_repr_debug_print_log(priv.partial); + SPDocumentPrivate &priv=*doc.priv; + Inkscape::XML::Event *log=sp_repr_commit_undoable(doc.rdoc); + if (log || priv.partial) { + g_warning ("Incomplete undo transaction:"); + priv.partial = sp_repr_coalesce_log(priv.partial, log); + sp_repr_debug_print_log(priv.partial); Inkscape::Event *event = new Inkscape::Event(priv.partial); - priv.undo.push_back(event); + priv.undo.push_back(event); priv.undoStackObservers.notifyUndoCommitEvent(event); - priv.partial = NULL; - } + priv.partial = NULL; + } } static void perform_document_update(SPDocument &doc) { @@ -238,100 +271,101 @@ static void perform_document_update(SPDocument &doc) { gboolean Inkscape::DocumentUndo::undo(SPDocument *doc) { - using Inkscape::Debug::EventTracker; - using Inkscape::Debug::SimpleEvent; + using Inkscape::Debug::EventTracker; + using Inkscape::Debug::SimpleEvent; - gboolean ret; + gboolean ret; - EventTracker > tracker("undo"); + EventTracker > tracker("undo"); - g_assert (doc != NULL); - g_assert (doc->priv != NULL); - g_assert (doc->priv->sensitive); + g_assert (doc != NULL); + g_assert (doc->priv != NULL); + g_assert (doc->priv->sensitive); - doc->priv->sensitive = FALSE; - doc->priv->seeking = true; + doc->priv->sensitive = FALSE; + doc->priv->seeking = true; - doc->actionkey.clear(); + doc->actionkey.clear(); - finish_incomplete_transaction(*doc); + finish_incomplete_transaction(*doc); - if (! doc->priv->undo.empty()) { - Inkscape::Event *log = doc->priv->undo.back(); - doc->priv->undo.pop_back(); - sp_repr_undo_log (log->event); - perform_document_update(*doc); + if (! doc->priv->undo.empty()) { + Inkscape::Event *log = doc->priv->undo.back(); + doc->priv->undo.pop_back(); + sp_repr_undo_log (log->event); + perform_document_update(*doc); - doc->priv->redo.push_back(log); + doc->priv->redo.push_back(log); - doc->setModifiedSinceSave(); - doc->priv->undoStackObservers.notifyUndoEvent(log); + doc->setModifiedSinceSave(); + doc->priv->undoStackObservers.notifyUndoEvent(log); - ret = TRUE; - } else { - ret = FALSE; - } + ret = TRUE; + } else { + ret = FALSE; + } - sp_repr_begin_transaction (doc->rdoc); + sp_repr_begin_transaction (doc->rdoc); - doc->priv->sensitive = TRUE; - doc->priv->seeking = false; + doc->priv->sensitive = TRUE; + doc->priv->seeking = false; - if (ret) - INKSCAPE.external_change(); + if (ret) + INKSCAPE.external_change(); - return ret; + return ret; } gboolean Inkscape::DocumentUndo::redo(SPDocument *doc) { - using Inkscape::Debug::EventTracker; - using Inkscape::Debug::SimpleEvent; + using Inkscape::Debug::EventTracker; + using Inkscape::Debug::SimpleEvent; - gboolean ret; + gboolean ret; - EventTracker > tracker("redo"); + EventTracker > tracker("redo"); - g_assert (doc != NULL); - g_assert (doc->priv != NULL); - g_assert (doc->priv->sensitive); + g_assert (doc != NULL); + g_assert (doc->priv != NULL); + g_assert (doc->priv->sensitive); - doc->priv->sensitive = FALSE; - doc->priv->seeking = true; + doc->priv->sensitive = FALSE; + doc->priv->seeking = true; - doc->actionkey.clear(); + doc->actionkey.clear(); - finish_incomplete_transaction(*doc); + finish_incomplete_transaction(*doc); - if (! doc->priv->redo.empty()) { - Inkscape::Event *log = doc->priv->redo.back(); - doc->priv->redo.pop_back(); - sp_repr_replay_log (log->event); - doc->priv->undo.push_back(log); + if (! doc->priv->redo.empty()) { + Inkscape::Event *log = doc->priv->redo.back(); + doc->priv->redo.pop_back(); + sp_repr_replay_log (log->event); + doc->priv->undo.push_back(log); - doc->setModifiedSinceSave(); - doc->priv->undoStackObservers.notifyRedoEvent(log); + doc->setModifiedSinceSave(); + doc->priv->undoStackObservers.notifyRedoEvent(log); - ret = TRUE; - } else { - ret = FALSE; - } + ret = TRUE; + } else { + ret = FALSE; + } - sp_repr_begin_transaction (doc->rdoc); + sp_repr_begin_transaction (doc->rdoc); - doc->priv->sensitive = TRUE; - doc->priv->seeking = false; + doc->priv->sensitive = TRUE; + doc->priv->seeking = false; - if (ret) - INKSCAPE.external_change(); + if (ret) + INKSCAPE.external_change(); - return ret; + return ret; } void Inkscape::DocumentUndo::clearUndo(SPDocument *doc) { if (! doc->priv->undo.empty()) doc->priv->undoStackObservers.notifyClearUndoEvent(); + while (! doc->priv->undo.empty()) { Inkscape::Event *e = doc->priv->undo.back(); doc->priv->undo.pop_back(); @@ -342,8 +376,8 @@ void Inkscape::DocumentUndo::clearUndo(SPDocument *doc) void Inkscape::DocumentUndo::clearRedo(SPDocument *doc) { - if (!doc->priv->redo.empty()) - doc->priv->undoStackObservers.notifyClearRedoEvent(); + if (!doc->priv->redo.empty()) + doc->priv->undoStackObservers.notifyClearRedoEvent(); while (! doc->priv->redo.empty()) { Inkscape::Event *e = doc->priv->redo.back(); diff --git a/src/document-undo.h b/src/document-undo.h index 85b44d562..b80b176d3 100644 --- a/src/document-undo.h +++ b/src/document-undo.h @@ -33,6 +33,10 @@ public: static bool getUndoSensitive(SPDocument const *document); + static void setUndoJoined(SPDocument *doc, bool join_undo); + + static bool getUndoJoined(SPDocument *doc); + static void clearUndo(SPDocument *document); static void clearRedo(SPDocument *document); diff --git a/src/document.cpp b/src/document.cpp index 7086fc0be..87f13f749 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -121,6 +121,7 @@ SPDocument::SPDocument() : p->serial = next_serial++; p->sensitive = false; + p->join_undo = false; p->partial = NULL; p->history_size = 0; p->seeking = false; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 7d32477a1..2c93c5496 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1031,7 +1031,7 @@ sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) C_("Undo action", "Raise")); } -void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *desktop) +void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *desktop, bool skip_undo) { SPDocument *document = selection->layers()->getDocument(); @@ -1055,9 +1055,10 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto Inkscape::XML::Node *repr =(*l); repr->setPosition(-1); } - - DocumentUndo::done(document, SP_VERB_SELECTION_TO_FRONT, - _("Raise to top")); + if (!skip_undo) { + DocumentUndo::done(document, SP_VERB_SELECTION_TO_FRONT, + _("Raise to top")); + } } void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) @@ -1115,7 +1116,7 @@ void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) C_("Undo action", "Lower")); } -void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *desktop) +void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *desktop, bool skip_undo) { SPDocument *document = selection->layers()->getDocument(); @@ -1149,9 +1150,10 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des } repr->setPosition(minpos); } - - DocumentUndo::done(document, SP_VERB_SELECTION_TO_BACK, - _("Lower to bottom")); + if (!skip_undo) { + DocumentUndo::done(document, SP_VERB_SELECTION_TO_BACK, + _("Lower to bottom")); + } } void @@ -3859,7 +3861,7 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) * If \a apply_clip_path parameter is true, clipPath is created, otherwise mask * */ -void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_to_layer) +void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_to_layer, bool skip_undo) { if (desktop == NULL) { return; @@ -4021,11 +4023,12 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ } selection->addList(items_to_select); - - if (apply_clip_path) { - DocumentUndo::done(doc, SP_VERB_OBJECT_SET_CLIPPATH, _("Set clipping path")); - } else { - DocumentUndo::done(doc, SP_VERB_OBJECT_SET_MASK, _("Set mask")); + if (!skip_undo) { + if (apply_clip_path) { + DocumentUndo::done(doc, SP_VERB_OBJECT_SET_CLIPPATH, _("Set clipping path")); + } else { + DocumentUndo::done(doc, SP_VERB_OBJECT_SET_MASK, _("Set mask")); + } } } diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index 82b91c617..31c160bf9 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -79,9 +79,9 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop); void sp_selection_ungroup_pop_selection(Inkscape::Selection *selection, SPDesktop *desktop); void sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop); -void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *desktop); +void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *desktop, bool skip_undo = false); void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop); -void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *desktop); +void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *desktop, bool skip_undo = false); SPCSSAttr *take_style_from_item (SPObject *object); @@ -157,7 +157,7 @@ void sp_document_get_export_hints (SPDocument * doc, Glib::ustring &filename, fl void sp_selection_create_bitmap_copy (SPDesktop *desktop); void sp_selection_set_clipgroup(SPDesktop *desktop); -void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_to_layer); +void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_to_layer, bool skip_undo = false); void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path); bool fit_canvas_to_selection(SPDesktop *, bool with_margins = false); diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index b62f68a5f..60b8c2792 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -644,6 +644,8 @@ void EraserTool::clear_current() { void EraserTool::set_to_accumulated() { bool workDone = false; SPDocument *document = this->desktop->doc(); + bool saved = DocumentUndo::getUndoSensitive(document); + DocumentUndo::setUndoSensitive(document, false); if (!this->accumulated->is_empty()) { if (!this->repr) { /* Create object */ @@ -721,7 +723,9 @@ void EraserTool::set_to_accumulated() { Inkscape::GC::release(dup); // parent takes over selection->set(dup); if (!this->nowidth) { - sp_selected_path_union(selection, desktop); + DocumentUndo::setUndoSensitive(document, saved); + sp_selected_path_union_skip_undo(selection, desktop); + DocumentUndo::setUndoSensitive(document, false); } selection->add(item); if(item->style->fill_rule.value == SP_WIND_RULE_EVENODD){ @@ -731,13 +735,16 @@ void EraserTool::set_to_accumulated() { sp_repr_css_attr_unref(css); css = 0; } + DocumentUndo::setUndoSensitive(document, saved); if (this->nowidth) { - sp_selected_path_cut(selection, desktop); + sp_selected_path_cut_skip_undo(selection, desktop); } else { - sp_selected_path_diff(selection, desktop); + sp_selected_path_diff_skip_undo(selection, desktop); } + DocumentUndo::setUndoSensitive(document, saved); workDone = true; // TODO set this only if something was cut. bool break_apart = prefs->getBool("/tools/eraser/break_apart", false); + DocumentUndo::setUndoSensitive(document, saved); if(!break_apart){ sp_selected_path_combine(desktop, true); } else { @@ -745,6 +752,7 @@ void EraserTool::set_to_accumulated() { sp_selected_path_break_apart(desktop, true); } } + DocumentUndo::setUndoSensitive(document, saved); if ( !selection->isEmpty() ) { // If the item was not completely erased, track the new remainder. std::vector nowSel(selection->itemList()); @@ -777,7 +785,9 @@ void EraserTool::set_to_accumulated() { this->repr->parent()->appendChild(dup); Inkscape::GC::release(dup); // parent takes over selection->set(dup); - sp_selected_path_union(selection, this->desktop); + DocumentUndo::setUndoSensitive(document, saved); + sp_selected_path_union_skip_undo(selection, this->desktop); + DocumentUndo::setUndoSensitive(document, false); sp_selection_raise_to_top(selection, this->desktop); if (bbox && bbox->intersects(*eraserBbox)) { SPClipPath *clip_path = item->clip_ref->getObject(); @@ -800,14 +810,19 @@ void EraserTool::set_to_accumulated() { sp_object_unref(rect); sp_selection_raise_to_top(selection, this->desktop); selection->add(dup_clip); - sp_selected_path_diff(selection, this->desktop); + DocumentUndo::setUndoSensitive(document, saved); + sp_selected_path_diff_skip_undo(selection, this->desktop); + DocumentUndo::setUndoSensitive(document, saved); SPItem * clip = SP_ITEM(selection->itemList()[0]); + DocumentUndo::setUndoSensitive(document, false); } } } } else { selection->add(rect); - sp_selected_path_diff(selection, this->desktop); + DocumentUndo::setUndoSensitive(document, saved); + sp_selected_path_diff_skip_undo(selection, this->desktop); + DocumentUndo::setUndoSensitive(document, false); } sp_selection_raise_to_top(selection, this->desktop); selection->add(item); @@ -863,6 +878,8 @@ void EraserTool::set_to_accumulated() { this->repr = 0; } } + document->setModifiedSinceSave(); + DocumentUndo::setUndoSensitive(document, saved); if ( workDone ) { DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_ERASER, _("Draw eraser stroke")); } else { -- cgit v1.2.3 From 3fcae9b041aae2e79732277cbcd20fc13a92d453 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 22 May 2016 00:13:36 +0200 Subject: Fixing undo thing (bzr r14865.1.7) --- src/ui/tools/eraser-tool.cpp | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 60b8c2792..2896e7b3e 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -723,10 +723,8 @@ void EraserTool::set_to_accumulated() { Inkscape::GC::release(dup); // parent takes over selection->set(dup); if (!this->nowidth) { - DocumentUndo::setUndoSensitive(document, saved); sp_selected_path_union_skip_undo(selection, desktop); - DocumentUndo::setUndoSensitive(document, false); - } + } selection->add(item); if(item->style->fill_rule.value == SP_WIND_RULE_EVENODD){ SPCSSAttr *css = sp_repr_css_attr_new(); @@ -735,16 +733,13 @@ void EraserTool::set_to_accumulated() { sp_repr_css_attr_unref(css); css = 0; } - DocumentUndo::setUndoSensitive(document, saved); if (this->nowidth) { sp_selected_path_cut_skip_undo(selection, desktop); } else { sp_selected_path_diff_skip_undo(selection, desktop); } - DocumentUndo::setUndoSensitive(document, saved); workDone = true; // TODO set this only if something was cut. bool break_apart = prefs->getBool("/tools/eraser/break_apart", false); - DocumentUndo::setUndoSensitive(document, saved); if(!break_apart){ sp_selected_path_combine(desktop, true); } else { @@ -752,7 +747,6 @@ void EraserTool::set_to_accumulated() { sp_selected_path_break_apart(desktop, true); } } - DocumentUndo::setUndoSensitive(document, saved); if ( !selection->isEmpty() ) { // If the item was not completely erased, track the new remainder. std::vector nowSel(selection->itemList()); @@ -785,10 +779,8 @@ void EraserTool::set_to_accumulated() { this->repr->parent()->appendChild(dup); Inkscape::GC::release(dup); // parent takes over selection->set(dup); - DocumentUndo::setUndoSensitive(document, saved); sp_selected_path_union_skip_undo(selection, this->desktop); - DocumentUndo::setUndoSensitive(document, false); - sp_selection_raise_to_top(selection, this->desktop); + sp_selection_raise_to_top(selection, this->desktop, true); if (bbox && bbox->intersects(*eraserBbox)) { SPClipPath *clip_path = item->clip_ref->getObject(); if (clip_path) { @@ -808,23 +800,18 @@ void EraserTool::set_to_accumulated() { sp_object_ref(rect, 0); rect->deleteObject(true); sp_object_unref(rect); - sp_selection_raise_to_top(selection, this->desktop); + sp_selection_raise_to_top(selection, this->desktop, true); selection->add(dup_clip); - DocumentUndo::setUndoSensitive(document, saved); sp_selected_path_diff_skip_undo(selection, this->desktop); - DocumentUndo::setUndoSensitive(document, saved); SPItem * clip = SP_ITEM(selection->itemList()[0]); - DocumentUndo::setUndoSensitive(document, false); } } } } else { selection->add(rect); - DocumentUndo::setUndoSensitive(document, saved); sp_selected_path_diff_skip_undo(selection, this->desktop); - DocumentUndo::setUndoSensitive(document, false); } - sp_selection_raise_to_top(selection, this->desktop); + sp_selection_raise_to_top(selection, this->desktop, true); selection->add(item); sp_selection_set_mask(this->desktop, true, false); } else { -- cgit v1.2.3 From e2f3d8631f30db820029835ecc6cdc68d339cdc0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 22 May 2016 01:33:30 +0200 Subject: Working undo (bzr r14865.1.8) --- src/ui/tools/eraser-tool.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 2896e7b3e..40e13a9cd 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -644,8 +644,6 @@ void EraserTool::clear_current() { void EraserTool::set_to_accumulated() { bool workDone = false; SPDocument *document = this->desktop->doc(); - bool saved = DocumentUndo::getUndoSensitive(document); - DocumentUndo::setUndoSensitive(document, false); if (!this->accumulated->is_empty()) { if (!this->repr) { /* Create object */ @@ -680,17 +678,17 @@ void EraserTool::set_to_accumulated() { std::vector toWorkOn; if (selection->isEmpty()) { if ( eraser_mode == 1 || eraser_mode == 2) { - toWorkOn = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *eraserBbox); + toWorkOn = document->getItemsPartiallyInBox(desktop->dkey, *eraserBbox); } else { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); - toWorkOn = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints()); + toWorkOn = document->getItemsAtPoints(desktop->dkey, r->getPoints()); } toWorkOn.erase(std::remove(toWorkOn.begin(), toWorkOn.end(), acid), toWorkOn.end()); } else { if ( eraser_mode == 0 ) { Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); std::vector touched; - touched = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints()); + touched = document->getItemsAtPoints(desktop->dkey, r->getPoints()); for (std::vector::const_iterator i = touched.begin();i!=touched.end();++i) { if(selection->includes(*i)){ toWorkOn.push_back((*i)); @@ -779,8 +777,8 @@ void EraserTool::set_to_accumulated() { this->repr->parent()->appendChild(dup); Inkscape::GC::release(dup); // parent takes over selection->set(dup); - sp_selected_path_union_skip_undo(selection, this->desktop); - sp_selection_raise_to_top(selection, this->desktop, true); + sp_selected_path_union_skip_undo(selection, desktop); + sp_selection_raise_to_top(selection, desktop, true); if (bbox && bbox->intersects(*eraserBbox)) { SPClipPath *clip_path = item->clip_ref->getObject(); if (clip_path) { @@ -800,20 +798,21 @@ void EraserTool::set_to_accumulated() { sp_object_ref(rect, 0); rect->deleteObject(true); sp_object_unref(rect); - sp_selection_raise_to_top(selection, this->desktop, true); + sp_selection_raise_to_top(selection, desktop, true); selection->add(dup_clip); - sp_selected_path_diff_skip_undo(selection, this->desktop); + sp_selected_path_diff_skip_undo(selection, desktop); SPItem * clip = SP_ITEM(selection->itemList()[0]); } } } } else { selection->add(rect); - sp_selected_path_diff_skip_undo(selection, this->desktop); + std::cout << "asasgfasfasfasfasfasf\n"; + sp_selected_path_diff_skip_undo(selection, desktop); } - sp_selection_raise_to_top(selection, this->desktop, true); + sp_selection_raise_to_top(selection, desktop, true); selection->add(item); - sp_selection_set_mask(this->desktop, true, false); + sp_selection_set_mask(desktop, true, false, true); } else { SPItem *erase_clip = selection->singleItem(); if (erase_clip) { @@ -843,7 +842,7 @@ void EraserTool::set_to_accumulated() { } if ( eraser_mode == 0 ) { - //sp_selection_delete(desktop); + sp_selection_delete(desktop); remainingItems.clear(); } @@ -865,12 +864,10 @@ void EraserTool::set_to_accumulated() { this->repr = 0; } } - document->setModifiedSinceSave(); - DocumentUndo::setUndoSensitive(document, saved); if ( workDone ) { - DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_ERASER, _("Draw eraser stroke")); + DocumentUndo::done(document, SP_VERB_CONTEXT_ERASER, _("Draw eraser stroke")); } else { - DocumentUndo::cancel(desktop->getDocument()); + DocumentUndo::cancel(document); } } -- cgit v1.2.3 From 331336b5f924ad3200a343f571178e19b55532a1 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 22 May 2016 04:13:59 +0200 Subject: Clip eraser done! Thanks Doctormon! (bzr r14865.1.9) --- src/ui/tools/eraser-tool.cpp | 165 ++++++++++++++++++++--------------------- src/widgets/eraser-toolbar.cpp | 12 ++- src/widgets/toolbox.cpp | 3 +- 3 files changed, 94 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 40e13a9cd..c5a068dfc 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -647,48 +647,48 @@ void EraserTool::set_to_accumulated() { if (!this->accumulated->is_empty()) { if (!this->repr) { /* Create object */ - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); /* Set style */ - sp_desktop_apply_style_tool (desktop, repr, "/tools/eraser", false); + sp_desktop_apply_style_tool (this->desktop, repr, "/tools/eraser", false); this->repr = repr; } - SPItem *item_repr = SP_ITEM(desktop->currentLayer()->appendChildRepr(this->repr)); + SPItem *item_repr = SP_ITEM(this->desktop->currentLayer()->appendChildRepr(this->repr)); Inkscape::GC::release(this->repr); item_repr->updateRepr(); - Geom::PathVector pathv = this->accumulated->get_pathvector() * desktop->dt2doc(); + Geom::PathVector pathv = this->accumulated->get_pathvector() * this->desktop->dt2doc(); pathv *= item_repr->i2doc_affine().inverse(); gchar *str = sp_svg_write_path(pathv); g_assert( str != NULL ); this->repr->setAttribute("d", str); g_free(str); - + Geom::OptRect eraserBbox; if ( this->repr ) { bool wasSelection = false; - Inkscape::Selection *selection = desktop->getSelection(); + Inkscape::Selection *selection = this->desktop->getSelection(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint eraser_mode = prefs->getInt("/tools/eraser/mode", 2); - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc(); - SPItem* acid = SP_ITEM(desktop->doc()->getObjectByRepr(this->repr)); - Geom::OptRect eraserBbox = acid->desktopVisualBounds(); + SPItem* acid = SP_ITEM(this->desktop->doc()->getObjectByRepr(this->repr)); + eraserBbox = acid->desktopVisualBounds(); std::vector remainingItems; std::vector toWorkOn; if (selection->isEmpty()) { if ( eraser_mode == 1 || eraser_mode == 2) { - toWorkOn = document->getItemsPartiallyInBox(desktop->dkey, *eraserBbox); + toWorkOn = document->getItemsPartiallyInBox(this->desktop->dkey, *eraserBbox); } else { - Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); - toWorkOn = document->getItemsAtPoints(desktop->dkey, r->getPoints()); + Inkscape::Rubberband *r = Inkscape::Rubberband::get(this->desktop); + toWorkOn = document->getItemsAtPoints(this->desktop->dkey, r->getPoints()); } toWorkOn.erase(std::remove(toWorkOn.begin(), toWorkOn.end(), acid), toWorkOn.end()); } else { if ( eraser_mode == 0 ) { - Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop); + Inkscape::Rubberband *r = Inkscape::Rubberband::get(this->desktop); std::vector touched; - touched = document->getItemsAtPoints(desktop->dkey, r->getPoints()); + touched = document->getItemsAtPoints(this->desktop->dkey, r->getPoints()); for (std::vector::const_iterator i = touched.begin();i!=touched.end();++i) { if(selection->includes(*i)){ toWorkOn.push_back((*i)); @@ -721,28 +721,28 @@ void EraserTool::set_to_accumulated() { Inkscape::GC::release(dup); // parent takes over selection->set(dup); if (!this->nowidth) { - sp_selected_path_union_skip_undo(selection, desktop); + sp_selected_path_union_skip_undo(selection, this->desktop); } selection->add(item); if(item->style->fill_rule.value == SP_WIND_RULE_EVENODD){ SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-rule", "evenodd"); - sp_desktop_set_style(desktop, css); + sp_desktop_set_style(this->desktop, css); sp_repr_css_attr_unref(css); css = 0; } if (this->nowidth) { - sp_selected_path_cut_skip_undo(selection, desktop); + sp_selected_path_cut_skip_undo(selection, this->desktop); } else { - sp_selected_path_diff_skip_undo(selection, desktop); + sp_selected_path_diff_skip_undo(selection, this->desktop); } workDone = true; // TODO set this only if something was cut. bool break_apart = prefs->getBool("/tools/eraser/break_apart", false); if(!break_apart){ - sp_selected_path_combine(desktop, true); + sp_selected_path_combine(this->desktop, true); } else { if(!this->nowidth){ - sp_selected_path_break_apart(desktop, true); + sp_selected_path_break_apart(this->desktop, true); } } if ( !selection->isEmpty() ) { @@ -758,76 +758,75 @@ void EraserTool::set_to_accumulated() { } } } else if ( eraser_mode == 2 ) { - remainingItems.clear(); - for (std::vector::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); ++i){ - selection->clear(); - SPItem *item = *i; - Geom::OptRect bbox = item->desktopVisualBounds(); - Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc(); - Inkscape::XML::Node *rect_repr = xml_doc->createElement("svg:rect"); - sp_desktop_apply_style_tool (desktop, rect_repr, "/tools/eraser", false); - SPRect * rect = SP_RECT(this->desktop->currentLayer()->appendChildRepr(rect_repr)); - Inkscape::GC::release(rect_repr); - - rect->updateRepr(); - rect->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height()); - rect->transform = SP_ITEM(desktop->currentLayer())->i2dt_affine().inverse(); - - Inkscape::XML::Node* dup = this->repr->duplicate(xml_doc); - this->repr->parent()->appendChild(dup); - Inkscape::GC::release(dup); // parent takes over - selection->set(dup); - sp_selected_path_union_skip_undo(selection, desktop); - sp_selection_raise_to_top(selection, desktop, true); - if (bbox && bbox->intersects(*eraserBbox)) { - SPClipPath *clip_path = item->clip_ref->getObject(); - if (clip_path) { - SPPath *clip_data = SP_PATH(clip_path->firstChild()); - if (clip_data) { - Inkscape::XML::Node *dup_clip = SP_OBJECT(clip_data)->getRepr()->duplicate(xml_doc); - if (dup_clip) { - SPItem * dup_clip_obj = SP_ITEM(item_repr->parent->appendChildRepr(dup_clip)); - if (dup_clip_obj) { - dup_clip_obj->doWriteTransform(dup_clip, item->transform); - sp_object_ref(clip_data, 0); - clip_data->deleteObject(true); - sp_object_unref(clip_data); - sp_object_ref(clip_path, 0); - clip_path->deleteObject(true); - sp_object_unref(clip_path); - sp_object_ref(rect, 0); - rect->deleteObject(true); - sp_object_unref(rect); - sp_selection_raise_to_top(selection, desktop, true); - selection->add(dup_clip); - sp_selected_path_diff_skip_undo(selection, desktop); - SPItem * clip = SP_ITEM(selection->itemList()[0]); + if (!this->nowidth) { + remainingItems.clear(); + for (std::vector::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); ++i){ + selection->clear(); + SPItem *item = *i; + Geom::OptRect bbox = item->desktopVisualBounds(); + Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc(); + Inkscape::XML::Node *rect_repr = xml_doc->createElement("svg:rect"); + sp_desktop_apply_style_tool (this->desktop, rect_repr, "/tools/eraser", false); + SPRect * rect = SP_RECT(this->desktop->currentLayer()->appendChildRepr(rect_repr)); + Inkscape::GC::release(rect_repr); + rect->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height()); + rect->transform = SP_ITEM(this->desktop->currentLayer())->i2dt_affine().inverse(); + rect->updateRepr(); + this->desktop->canvas->endForcedFullRedraws(); + Inkscape::XML::Node* dup = this->repr->duplicate(xml_doc); + this->repr->parent()->appendChild(dup); + Inkscape::GC::release(dup); // parent takes over + selection->set(dup); + sp_selected_path_union_skip_undo(selection, this->desktop); + sp_selection_raise_to_top(selection, this->desktop, true); + if (bbox && bbox->intersects(*eraserBbox)) { + SPClipPath *clip_path = item->clip_ref->getObject(); + if (clip_path) { + SPPath *clip_data = SP_PATH(clip_path->firstChild()); + if (clip_data) { + Inkscape::XML::Node *dup_clip = SP_OBJECT(clip_data)->getRepr()->duplicate(xml_doc); + if (dup_clip) { + SPItem * dup_clip_obj = SP_ITEM(item_repr->parent->appendChildRepr(dup_clip)); + if (dup_clip_obj) { + dup_clip_obj->doWriteTransform(dup_clip, item->transform); + sp_object_ref(clip_data, 0); + clip_data->deleteObject(true); + sp_object_unref(clip_data); + sp_object_ref(clip_path, 0); + clip_path->deleteObject(true); + sp_object_unref(clip_path); + sp_object_ref(rect, 0); + rect->deleteObject(true); + sp_object_unref(rect); + sp_selection_raise_to_top(selection, this->desktop, true); + selection->add(dup_clip); + sp_selected_path_diff_skip_undo(selection, this->desktop); + SPItem * clip = SP_ITEM(selection->itemList()[0]); + } } } + } else { + selection->add(rect); + sp_selected_path_diff_skip_undo(selection, this->desktop); } + sp_selection_raise_to_top(selection, this->desktop, true); + selection->add(item); + sp_selection_set_mask(this->desktop, true, false, true); } else { - selection->add(rect); - std::cout << "asasgfasfasfasfasfasf\n"; - sp_selected_path_diff_skip_undo(selection, desktop); + SPItem *erase_clip = selection->singleItem(); + if (erase_clip) { + sp_object_ref(erase_clip, 0); + erase_clip->deleteObject(true); + sp_object_unref(erase_clip); + } } - sp_selection_raise_to_top(selection, desktop, true); - selection->add(item); - sp_selection_set_mask(desktop, true, false, true); - } else { - SPItem *erase_clip = selection->singleItem(); - if (erase_clip) { - sp_object_ref(erase_clip, 0); - erase_clip->deleteObject(true); - sp_object_unref(erase_clip); + workDone = true; + selection->clear(); + if (wasSelection) { + remainingItems.push_back(item); } } - workDone = true; - selection->clear(); - if (wasSelection) { - remainingItems.push_back(item); - } } - } else { for (std::vector ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();++i) { sp_object_ref( *i, 0 ); @@ -842,7 +841,7 @@ void EraserTool::set_to_accumulated() { } if ( eraser_mode == 0 ) { - sp_selection_delete(desktop); + sp_selection_delete(this->desktop); remainingItems.clear(); } diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp index f69ac633f..482075dc6 100644 --- a/src/widgets/eraser-toolbar.cpp +++ b/src/widgets/eraser-toolbar.cpp @@ -76,7 +76,11 @@ static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) GtkAction *mass = GTK_ACTION( g_object_get_data(tbl, "mass") ); GtkAction *width = GTK_ACTION( g_object_get_data(tbl, "width") ); if(eraser_mode != 0){ - gtk_action_set_visible( split, TRUE ); + if(eraser_mode == 1) { + gtk_action_set_visible( split, TRUE ); + } else { + gtk_action_set_visible( split, FALSE ); + } gtk_action_set_visible( mass, TRUE ); gtk_action_set_visible( width, TRUE ); } else { @@ -204,7 +208,11 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb GtkAction *mass = GTK_ACTION( g_object_get_data(holder, "mass") ); GtkAction *width = GTK_ACTION( g_object_get_data(holder, "width") ); if (eraser_mode != 0) { - gtk_action_set_visible( split, TRUE ); + if(eraser_mode == 1) { + gtk_action_set_visible( split, TRUE ); + } else { + gtk_action_set_visible( split, FALSE ); + } gtk_action_set_visible( mass, TRUE ); gtk_action_set_visible( width, TRUE ); } else { diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index f7b5e585f..8113c9619 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -499,9 +499,10 @@ static gchar const * ui_descr = " " " " " " - " " " " " " + " " + " " " " " " -- cgit v1.2.3 From c230ee02c2732c7eb55c5bdc6ef846f88550eea3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 22 May 2016 17:44:25 +0200 Subject: first attem to work throught layers (bzr r14865.1.11) --- src/ui/tools/eraser-tool.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index c5a068dfc..02908fdf9 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -61,6 +61,7 @@ #include "sp-clippath.h" #include "sp-rect.h" #include "sp-text.h" +#include "sp-root.h" #include "display/canvas-bpath.h" #include "display/canvas-arena.h" #include "livarot/Shape.h" @@ -655,7 +656,7 @@ void EraserTool::set_to_accumulated() { this->repr = repr; } - SPItem *item_repr = SP_ITEM(this->desktop->currentLayer()->appendChildRepr(this->repr)); + SPItem *item_repr = SP_ITEM(SP_OBJECT(document->getRoot())->appendChildRepr(this->repr)); Inkscape::GC::release(this->repr); item_repr->updateRepr(); Geom::PathVector pathv = this->accumulated->get_pathvector() * this->desktop->dt2doc(); @@ -722,7 +723,7 @@ void EraserTool::set_to_accumulated() { selection->set(dup); if (!this->nowidth) { sp_selected_path_union_skip_undo(selection, this->desktop); - } + } selection->add(item); if(item->style->fill_rule.value == SP_WIND_RULE_EVENODD){ SPCSSAttr *css = sp_repr_css_attr_new(); @@ -767,10 +768,10 @@ void EraserTool::set_to_accumulated() { Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc(); Inkscape::XML::Node *rect_repr = xml_doc->createElement("svg:rect"); sp_desktop_apply_style_tool (this->desktop, rect_repr, "/tools/eraser", false); - SPRect * rect = SP_RECT(this->desktop->currentLayer()->appendChildRepr(rect_repr)); + SPRect * rect = SP_RECT(item_repr->parent->appendChildRepr(rect_repr)); Inkscape::GC::release(rect_repr); rect->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height()); - rect->transform = SP_ITEM(this->desktop->currentLayer())->i2dt_affine().inverse(); + rect->transform = SP_ITEM(rect->parent)->i2dt_affine().inverse(); rect->updateRepr(); this->desktop->canvas->endForcedFullRedraws(); Inkscape::XML::Node* dup = this->repr->duplicate(xml_doc); -- cgit v1.2.3 From 2d1b3b926c94db73a3f5cb73071027b9ee348154 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 22 May 2016 18:17:49 +0200 Subject: Speed improvements (bzr r14865.1.12) --- src/ui/tools/eraser-tool.cpp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 02908fdf9..5cd04fa6f 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -766,20 +766,11 @@ void EraserTool::set_to_accumulated() { SPItem *item = *i; Geom::OptRect bbox = item->desktopVisualBounds(); Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc(); - Inkscape::XML::Node *rect_repr = xml_doc->createElement("svg:rect"); - sp_desktop_apply_style_tool (this->desktop, rect_repr, "/tools/eraser", false); - SPRect * rect = SP_RECT(item_repr->parent->appendChildRepr(rect_repr)); - Inkscape::GC::release(rect_repr); - rect->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height()); - rect->transform = SP_ITEM(rect->parent)->i2dt_affine().inverse(); - rect->updateRepr(); - this->desktop->canvas->endForcedFullRedraws(); Inkscape::XML::Node* dup = this->repr->duplicate(xml_doc); this->repr->parent()->appendChild(dup); Inkscape::GC::release(dup); // parent takes over selection->set(dup); sp_selected_path_union_skip_undo(selection, this->desktop); - sp_selection_raise_to_top(selection, this->desktop, true); if (bbox && bbox->intersects(*eraserBbox)) { SPClipPath *clip_path = item->clip_ref->getObject(); if (clip_path) { @@ -790,15 +781,9 @@ void EraserTool::set_to_accumulated() { SPItem * dup_clip_obj = SP_ITEM(item_repr->parent->appendChildRepr(dup_clip)); if (dup_clip_obj) { dup_clip_obj->doWriteTransform(dup_clip, item->transform); - sp_object_ref(clip_data, 0); - clip_data->deleteObject(true); - sp_object_unref(clip_data); sp_object_ref(clip_path, 0); clip_path->deleteObject(true); sp_object_unref(clip_path); - sp_object_ref(rect, 0); - rect->deleteObject(true); - sp_object_unref(rect); sp_selection_raise_to_top(selection, this->desktop, true); selection->add(dup_clip); sp_selected_path_diff_skip_undo(selection, this->desktop); @@ -807,6 +792,15 @@ void EraserTool::set_to_accumulated() { } } } else { + Inkscape::XML::Node *rect_repr = xml_doc->createElement("svg:rect"); + sp_desktop_apply_style_tool (this->desktop, rect_repr, "/tools/eraser", false); + SPRect * rect = SP_RECT(item_repr->parent->appendChildRepr(rect_repr)); + Inkscape::GC::release(rect_repr); + rect->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height()); + rect->transform = SP_ITEM(rect->parent)->i2dt_affine().inverse(); + rect->updateRepr(); + rect->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + sp_selection_raise_to_top(selection, this->desktop, true); selection->add(rect); sp_selected_path_diff_skip_undo(selection, this->desktop); } -- cgit v1.2.3 From d7887bf24bbb703739e56fa9056e1c67d8483b4c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 22 May 2016 20:44:21 +0200 Subject: Added some widgets from caligraphic tool (bzr r14865.1.13) --- src/widgets/eraser-toolbar.cpp | 113 ++++++++++++++++++++++++++++++++++++++++- src/widgets/toolbox.cpp | 7 +++ 2 files changed, 119 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp index 482075dc6..ddfe31d72 100644 --- a/src/widgets/eraser-toolbar.cpp +++ b/src/widgets/eraser-toolbar.cpp @@ -64,6 +64,28 @@ static void sp_erc_mass_value_changed( GtkAdjustment *adj, GObject* tbl ) update_presets_list(tbl); } +static void sp_erc_velthin_value_changed( GtkAdjustment *adj, GObject* tbl ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/tools/eraser/thinning", gtk_adjustment_get_value(adj) ); + update_presets_list(tbl); +} + +static void sp_erc_cap_rounding_value_changed( GtkAdjustment *adj, GObject* tbl ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble( "/tools/eraser/cap_rounding", gtk_adjustment_get_value(adj) ); + update_presets_list(tbl); +} + +static void sp_erc_tremor_value_changed( GtkAdjustment *adj, GObject* tbl ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble( "/tools/eraser/tremor", gtk_adjustment_get_value(adj) ); + update_presets_list(tbl); +} + + static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) { SPDesktop *desktop = static_cast(g_object_get_data( tbl, "desktop" )); @@ -75,15 +97,27 @@ static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) GtkAction *split = GTK_ACTION( g_object_get_data(tbl, "split") ); GtkAction *mass = GTK_ACTION( g_object_get_data(tbl, "mass") ); GtkAction *width = GTK_ACTION( g_object_get_data(tbl, "width") ); - if(eraser_mode != 0){ + GtkAction *usepressure = GTK_ACTION( g_object_get_data(tbl, "usepressure") ); + GtkAction *cap_rounding = GTK_ACTION( g_object_get_data(tbl, "cap_rounding") ); + GtkAction *thinning = GTK_ACTION( g_object_get_data(tbl, "thinning") ); + GtkAction *tremor = GTK_ACTION( g_object_get_data(tbl, "tremor") ); + if (eraser_mode != 0) { if(eraser_mode == 1) { gtk_action_set_visible( split, TRUE ); } else { gtk_action_set_visible( split, FALSE ); } + gtk_action_set_visible(usepressure, TRUE ); + gtk_action_set_visible(tremor, TRUE ); + gtk_action_set_visible(cap_rounding, TRUE ); + gtk_action_set_visible(thinning, TRUE ); gtk_action_set_visible( mass, TRUE ); gtk_action_set_visible( width, TRUE ); } else { + gtk_action_set_visible(usepressure, FALSE ); + gtk_action_set_visible(tremor, FALSE ); + gtk_action_set_visible(cap_rounding, FALSE ); + gtk_action_set_visible(thinning, FALSE ); gtk_action_set_visible( split, FALSE ); gtk_action_set_visible( mass, FALSE ); gtk_action_set_visible( width, FALSE ); @@ -175,6 +209,71 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb g_object_set_data( holder, "width", eact ); gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); } + /* Use Pressure button */ + { + InkToggleAction* act = ink_toggle_action_new( "EraserPressureAction", + _("Eraser Pressure"), + _("Use the pressure of the input device to alter the width of the pen"), + INKSCAPE_ICON("draw-use-pressure"), + Inkscape::ICON_SIZE_DECORATION ); + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/eraser/usepressure", update_presets_list, holder); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + g_object_set_data( holder, "usepressure", act ); + } + { + + /* Thinning */ + gchar const* labels[] = {_("(speed blows up stroke)"), 0, 0, _("(slight widening)"), _("(constant width)"), _("(slight thinning, default)"), 0, 0, _("(speed deflates stroke)")}; + gdouble values[] = {-100, -40, -20, -10, 0, 10, 20, 40, 100}; + EgeAdjustmentAction* eact = create_adjustment_action( "EraserThinningAction", + _("Eraser Stroke Thinning"), _("Thinning:"), + _("How much velocity thins the stroke (> 0 makes fast strokes thinner, < 0 makes them broader, 0 makes width independent of velocity)"), + "/tools/eraser/thinning", 10, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + -100, 100, 1, 10.0, + labels, values, G_N_ELEMENTS(labels), + sp_erc_velthin_value_changed, NULL /*unit tracker*/, 1, 0); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + g_object_set_data( holder, "thinning", eact ); + gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + } + { + /* Cap Rounding */ + gchar const* labels[] = {_("(blunt caps, default)"), _("(slightly bulging)"), 0, 0, _("(approximately round)"), _("(long protruding caps)")}; + gdouble values[] = {0, 0.3, 0.5, 1.0, 1.4, 5.0}; + // TRANSLATORS: "cap" means "end" (both start and finish) here + EgeAdjustmentAction* eact = create_adjustment_action( "EraserCapRoundingAction", + _("Eraser Cap rounding"), _("Caps:"), + _("Increase to make caps at the ends of strokes protrude more (0 = no caps, 1 = round caps)"), + "/tools/eraser/cap_rounding", 0.0, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + 0.0, 5.0, 0.01, 0.1, + labels, values, G_N_ELEMENTS(labels), + sp_erc_cap_rounding_value_changed, NULL /*unit tracker*/, 0.01, 2 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + g_object_set_data( holder, "cap_rounding", eact ); + gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + } + + { + /* Tremor */ + gchar const* labels[] = {_("(smooth line)"), _("(slight tremor)"), _("(noticeable tremor)"), 0, 0, _("(maximum tremor)")}; + gdouble values[] = {0, 10, 20, 40, 60, 100}; + EgeAdjustmentAction* eact = create_adjustment_action( "EraserTremorAction", + _("EraserStroke Tremor"), _("Tremor:"), + _("Increase to make strokes rugged and trembling"), + "/tools/eraser/tremor", 0.0, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + 0.0, 100, 1, 10.0, + labels, values, G_N_ELEMENTS(labels), + sp_erc_tremor_value_changed, NULL /*unit tracker*/, 1, 0); + + ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT ); + g_object_set_data( holder, "tremor", eact ); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + } { /* Mass */ gchar const* labels[] = {_("(no inertia)"), _("(slight smoothing, default)"), _("(noticeable lagging)"), 0, 0, _("(maximum inertia)")}; @@ -207,15 +306,27 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb GtkAction *split = GTK_ACTION( g_object_get_data(holder, "split") ); GtkAction *mass = GTK_ACTION( g_object_get_data(holder, "mass") ); GtkAction *width = GTK_ACTION( g_object_get_data(holder, "width") ); + GtkAction *usepressure = GTK_ACTION( g_object_get_data(holder, "usepressure") ); + GtkAction *cap_rounding = GTK_ACTION( g_object_get_data(holder, "cap_rounding") ); + GtkAction *thinning = GTK_ACTION( g_object_get_data(holder, "thinning") ); + GtkAction *tremor = GTK_ACTION( g_object_get_data(holder, "tremor") ); if (eraser_mode != 0) { if(eraser_mode == 1) { gtk_action_set_visible( split, TRUE ); } else { gtk_action_set_visible( split, FALSE ); } + gtk_action_set_visible(usepressure, TRUE ); + gtk_action_set_visible(tremor, TRUE ); + gtk_action_set_visible(cap_rounding, TRUE ); + gtk_action_set_visible(thinning, TRUE ); gtk_action_set_visible( mass, TRUE ); gtk_action_set_visible( width, TRUE ); } else { + gtk_action_set_visible(usepressure, FALSE ); + gtk_action_set_visible(tremor, FALSE ); + gtk_action_set_visible(cap_rounding, FALSE ); + gtk_action_set_visible(thinning, FALSE ); gtk_action_set_visible( split, FALSE ); gtk_action_set_visible( mass, FALSE ); gtk_action_set_visible( width, FALSE ); diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 8113c9619..52b31e4c5 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -499,6 +499,13 @@ static gchar const * ui_descr = " " " " " " + " " + " " + " " + " " + " " + " " + " " " " " " " " -- 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 46bff7b31a99784086c5f5589956e647c862e944 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sat, 4 Jun 2016 20:02:59 +0530 Subject: Register style dialog with support to add selector (bzr r14949.1.1) --- src/menus-skeleton.h | 1 + src/ui/CMakeLists.txt | 2 + src/ui/dialog/dialog-manager.cpp | 3 ++ src/ui/dialog/styledialog.cpp | 113 +++++++++++++++++++++++++++++++++++++++ src/ui/dialog/styledialog.h | 69 ++++++++++++++++++++++++ src/verbs.cpp | 5 ++ src/verbs.h | 1 + 7 files changed, 194 insertions(+) create mode 100644 src/ui/dialog/styledialog.cpp create mode 100644 src/ui/dialog/styledialog.h (limited to 'src') diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h index 9c7c65140..9b8586ec2 100644 --- a/src/menus-skeleton.h +++ b/src/menus-skeleton.h @@ -183,6 +183,7 @@ static char const menus_skeleton[] = " \n" " \n" " \n" +" \n" " \n" " \n" " \n" diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index 587974b90..4be3fa3d2 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -99,6 +99,7 @@ set(ui_SRC dialog/print-colors-preview-dialog.cpp dialog/print.cpp dialog/spellcheck.cpp + dialog/styledialog.cpp dialog/svg-fonts-dialog.cpp dialog/swatches.cpp dialog/symbols.cpp @@ -240,6 +241,7 @@ set(ui_SRC dialog/print-colors-preview-dialog.h dialog/print.h dialog/spellcheck.h + dialog/styledialog.h dialog/svg-fonts-dialog.h dialog/swatches.h dialog/symbols.h diff --git a/src/ui/dialog/dialog-manager.cpp b/src/ui/dialog/dialog-manager.cpp index 49853277c..4bb5215fd 100644 --- a/src/ui/dialog/dialog-manager.cpp +++ b/src/ui/dialog/dialog-manager.cpp @@ -60,6 +60,7 @@ #include "ui/dialog/svg-fonts-dialog.h" #include "ui/dialog/objects.h" #include "ui/dialog/tags.h" +#include "ui/dialog/styledialog.h" namespace Inkscape { namespace UI { @@ -128,6 +129,7 @@ DialogManager::DialogManager() { registerFactory("Swatches", &create); registerFactory("TileDialog", &create); registerFactory("Symbols", &create); + registerFactory("StyleDialog", &create); #if HAVE_POTRACE registerFactory("Trace", &create); @@ -167,6 +169,7 @@ DialogManager::DialogManager() { registerFactory("Swatches", &create); registerFactory("TileDialog", &create); registerFactory("Symbols", &create); + registerFactory("StyleDialog", &create); #if HAVE_POTRACE registerFactory("Trace", &create); diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp new file mode 100644 index 000000000..7e555ddb2 --- /dev/null +++ b/src/ui/dialog/styledialog.cpp @@ -0,0 +1,113 @@ +#include "styledialog.h" +#include "widgets/icon.h" +#include "verbs.h" +#include "sp-object.h" +#include "selection.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +void StyleDialog::_styleButton(Gtk::Button& btn, char const* iconName, + char const* tooltip) +{ + GtkWidget *child = sp_icon_new(Inkscape::ICON_SIZE_SMALL_TOOLBAR, iconName); + gtk_widget_show(child); + btn.add(*manage(Glib::wrap(child))); + btn.set_relief(Gtk::RELIEF_NONE); + btn.set_tooltip_text (tooltip); +} + +/** + * Constructor + * A treeview and a set of two buttons are added to the dialog. _addSelector + * adds selectors to treeview. Currently, delete button is disabled. + */ +StyleDialog::StyleDialog() : + UI::Widget::Panel("", "/dialogs/style", SP_VERB_DIALOG_STYLE), + _desktop(0) +{ + set_size_request(200, 200); + add(_mainBox); + + _mainBox.pack_start(_scrolledWindow, Gtk::PACK_EXPAND_WIDGET); + _treeView.set_headers_visible(false); + _scrolledWindow.add(_treeView); + _scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); + + _store = Gtk::ListStore::create(_mColumns); + _treeView.set_model(_store); + _treeView.append_column("Selector Number", _mColumns._selectorNumber); + _treeView.append_column("Selector Name", _mColumns._selectorLabel); + + Gtk::Button* create = manage( new Gtk::Button() ); + _styleButton(*create, "list-add", "Add a new CSS Selector"); + create->signal_clicked().connect(sigc::mem_fun(*this, + &StyleDialog::_addSelector)); + + Gtk::Button* del = manage( new Gtk::Button() ); + _styleButton(*del, "list-remove", "Remove a CSS Selector"); + del->set_sensitive(false); + + _mainBox.pack_start(_buttonBox, Gtk::PACK_SHRINK); + _buttonBox.pack_start(*create, Gtk::PACK_SHRINK); + _buttonBox.pack_start(*del, Gtk::PACK_SHRINK); + + SPDesktop* targetDesktop = getDesktop(); + setDesktop(targetDesktop); +} + +StyleDialog::~StyleDialog() +{ + setDesktop(NULL); +} + +void StyleDialog::setDesktop( SPDesktop* desktop ) +{ + Panel::setDesktop(desktop); + _desktop = Panel::getDesktop(); +} + +void StyleDialog::_addSelector() +{ + Gtk::TreeModel::Row row = *(_store->append()); + + /** + * On clicking '+' button, an entrybox with default text opens up. If an + * object is already selected, 'class' attribute with value in the entry + * is added to the selected object. + */ + Gtk::Dialog *textDialogPtr = new Gtk::Dialog(); + Gtk::Entry *textEditPtr = manage ( new Gtk::Entry() ); + textDialogPtr->add_button("Add", Gtk::RESPONSE_OK); + textDialogPtr->get_vbox()->pack_start(*textEditPtr, Gtk::PACK_SHRINK); + textEditPtr->set_text("Class1"); + + textDialogPtr->set_size_request(200, 100); + textDialogPtr->show_all(); + int result = textDialogPtr->run(); + static int number = 1; + + switch (result) { + case Gtk::RESPONSE_OK: + textDialogPtr->hide(); + row[_mColumns._selectorNumber] = number; + row[_mColumns._selectorLabel] = textEditPtr->get_text(); + number++; + break; + default: + break; + } + + if (_desktop->selection) { + std::vector selected = _desktop->getSelection()->list(); + for (int i = 0; i < selected.size(); ++i ) { + SPObject *obj = selected.at(i); + obj->setAttribute("class", textEditPtr->get_text()); + } + } +} + +} // namespace Dialog +} // namespace UI +} // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h new file mode 100644 index 000000000..044737add --- /dev/null +++ b/src/ui/dialog/styledialog.h @@ -0,0 +1,69 @@ +/** @file + * @brief A dialog for CSS selectors + */ +/* Authors: + * Kamalpreet Kaur Grewal + * + * Copyright (C) Kamalpreet Kaur Grewal 2016 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef STYLEDIALOG_H +#define STYLEDIALOG_H + +#include +#include +#include +#include +#include + +#include "desktop.h" + +namespace Inkscape { +namespace UI { +namespace Dialog { + +/** + * @brief The StyleDialog class + * A list of CSS selectors will show up in this dialog. + */ + +class StyleDialog : public UI::Widget::Panel +{ +public: + StyleDialog(); + ~StyleDialog(); + + static StyleDialog &getInstance() { return *new StyleDialog(); } + void setDesktop( SPDesktop* desktop); + +private: + void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); + + class ModelColumns : public Gtk::TreeModel::ColumnRecord + { + public: + ModelColumns() + { add(_selectorNumber); add(_selectorLabel); } + Gtk::TreeModelColumn _selectorNumber; + Gtk::TreeModelColumn _selectorLabel; + }; + + SPDesktop* _desktop; + ModelColumns _mColumns; + Gtk::VBox _mainBox; + Gtk::HBox _buttonBox; + Gtk::TreeView _treeView; + Glib::RefPtr _store; + Gtk::ScrolledWindow _scrolledWindow; + + // Signal handlers + void _addSelector(); +}; + +} // namespace Dialog +} // namespace UI +} // namespace Inkscape + +#endif // STYLEDIALOG_H diff --git a/src/verbs.cpp b/src/verbs.cpp index 299cfe8e7..2908ae580 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -2119,6 +2119,9 @@ void DialogVerb::perform(SPAction *action, void *data) case SP_VERB_DIALOG_PRINT_COLORS_PREVIEW: dt->_dlg_mgr->showDialog("PrintColorsPreviewDialog"); break; + case SP_VERB_DIALOG_STYLE: + dt->_dlg_mgr->showDialog("StyleDialog"); + break; default: break; @@ -2949,6 +2952,8 @@ Verb *Verb::_base_verbs[] = { N_("View Objects"), INKSCAPE_ICON("dialog-layers")), new DialogVerb(SP_VERB_DIALOG_TAGS, "DialogTags", N_("Selection se_ts..."), N_("View Tags"), INKSCAPE_ICON("edit-select-all-layers")), + new DialogVerb(SP_VERB_DIALOG_STYLE, "DialogStyle", N_("Style Dialog..."), + N_("View Style Dialog"), NULL), new DialogVerb(SP_VERB_DIALOG_LIVE_PATH_EFFECT, "DialogLivePathEffect", N_("Path E_ffects ..."), N_("Manage, edit, and apply path effects"), INKSCAPE_ICON("dialog-path-effects")), new DialogVerb(SP_VERB_DIALOG_FILTER_EFFECTS, "DialogFilterEffects", N_("Filter _Editor..."), diff --git a/src/verbs.h b/src/verbs.h index ffb9b23d8..35a9ca738 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -308,6 +308,7 @@ enum { SP_VERB_DIALOG_LAYERS, SP_VERB_DIALOG_OBJECTS, SP_VERB_DIALOG_TAGS, + SP_VERB_DIALOG_STYLE, SP_VERB_DIALOG_LIVE_PATH_EFFECT, SP_VERB_DIALOG_FILTER_EFFECTS, SP_VERB_DIALOG_SVG_FONTS, -- cgit v1.2.3 From 9abb5e658d005b3ac82afeec13fd59384a8e65eb Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Sun, 5 Jun 2016 23:20:55 +0200 Subject: Added object set (bzr r14954.1.1) --- src/CMakeLists.txt | 4 ++ src/object-set.cpp | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/object-set.h | 58 +++++++++++++++++++++++ src/object.cpp | 50 ++++++++++++++++++++ src/object.h | 76 ++++++++++++++++++++++++++++++ 5 files changed, 321 insertions(+) create mode 100644 src/object-set.cpp create mode 100644 src/object-set.h create mode 100644 src/object.cpp create mode 100644 src/object.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index df25728f4..802a79c4f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -229,7 +229,9 @@ set(inkscape_SRC message-context.cpp message-stack.cpp mod360.cpp + object.cpp object-hierarchy.cpp + object-set.cpp object-snapper.cpp path-chemistry.cpp persp3d-reference.cpp @@ -353,7 +355,9 @@ set(inkscape_SRC mod360-test.h mod360.h number-opt-number.h + object.h object-hierarchy.h + object-set.h object-snapper.h object-test.h path-chemistry.h diff --git a/src/object-set.cpp b/src/object-set.cpp new file mode 100644 index 000000000..f071aa4d6 --- /dev/null +++ b/src/object-set.cpp @@ -0,0 +1,133 @@ +/* + * Multiindex container for selection + * + * Authors: + * Adrian Boguszewski + * + * Copyright (C) 2016 Adrian Boguszewski + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "object-set.h" + +bool ObjectSet::add(Object* object) { + // any ancestor is in the set - do nothing + if (_anyAncestorIsInSet(object)) { + return false; + } + + // check if there is mutual ancestor for some elements, which can replace all of them in the set + Object* o = _getMutualAncestor(object); + + // remove all descendants from the set + _removeDescendantsFromSet(o); + + _add(o); + return true; +} + +bool ObjectSet::remove(Object* object) { + // object is the top of subtree + if (contains(object)) { + _remove(object); + return true; + } + + // any ancestor of object is in the set + if (_anyAncestorIsInSet(object)) { + _removeAncestorsFromSet(object); + return true; + } + + // no object nor any parent in the set + return false; +} + +bool ObjectSet::contains(Object* object) { + return container.get().find(object) != container.get().end(); +} + +void ObjectSet::clear() { + for (auto object: container) { + _remove(object); + } +} + +int ObjectSet::size() { + return container.size(); +} + +bool ObjectSet::_anyAncestorIsInSet(Object *object) { + Object* o = object; + while (o != nullptr) { + if (contains(o)) { + return true; + } + o = o->getParent(); + } + + return false; +} + +void ObjectSet::_removeDescendantsFromSet(Object *object) { + for (auto& child: object->getChildren()) { + if (contains(&child)) { + _remove(&child); + // there is certainly no children of this child in the set + continue; + } + + _removeDescendantsFromSet(&child); + } +} + +void ObjectSet::_remove(Object *object) { + releaseConnections[object].disconnect(); + releaseConnections.erase(object); + container.get().erase(object); +} + +void ObjectSet::_add(Object *object) { + releaseConnections[object] = object->connectRelease(sigc::mem_fun(*this, &ObjectSet::remove)); + container.push_back(object); +} + +Object *ObjectSet::_getMutualAncestor(Object *object) { + Object *o = object; + + bool flag = true; + while (o->getParent() != nullptr) { + for (auto &child: o->getParent()->getChildren()) { + if(&child != o && !contains(&child)) { + flag = false; + break; + } + } + if (!flag) { + break; + } + o = o->getParent(); + } + return o; +} + +void ObjectSet::_removeAncestorsFromSet(Object *object) { + Object* o = object; + while (o->getParent() != nullptr) { + for (auto &child: o->getParent()->getChildren()) { + if (&child != o) { + _add(&child); + } + } + if (contains(o->getParent())) { + _remove(o->getParent()); + break; + } + o = o->getParent(); + } +} + +ObjectSet::~ObjectSet() { + clear(); +} diff --git a/src/object-set.h b/src/object-set.h new file mode 100644 index 000000000..a3962356b --- /dev/null +++ b/src/object-set.h @@ -0,0 +1,58 @@ +/* + * Multiindex container for selection + * + * Authors: + * Adrian Boguszewski + * + * Copyright (C) 2016 Adrian Boguszewski + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef INKSCAPE_PROTOTYPE_OBJECTSET_H +#define INKSCAPE_PROTOTYPE_OBJECTSET_H + +#include "object.h" +#include +#include +#include +#include +#include +#include +#include + +struct hashed{}; + +typedef boost::multi_index_container< + Object*, + boost::multi_index::indexed_by< + boost::multi_index::sequenced<>, + boost::multi_index::hashed_unique< + boost::multi_index::tag, + boost::multi_index::identity> + >> multi_index_container; + +class ObjectSet { +public: + ObjectSet() {}; + ~ObjectSet(); + bool add(Object* object); + bool remove(Object* object); + bool contains(Object* object); + void clear(); + int size(); + +private: + void _add(Object* object); + void _remove(Object* object); + bool _anyAncestorIsInSet(Object *object); + void _removeDescendantsFromSet(Object *object); + void _removeAncestorsFromSet(Object *object); + Object *_getMutualAncestor(Object *object); + + multi_index_container container; + std::unordered_map releaseConnections; +}; + + +#endif //INKSCAPE_PROTOTYPE_OBJECTSET_H diff --git a/src/object.cpp b/src/object.cpp new file mode 100644 index 000000000..c05d50b3a --- /dev/null +++ b/src/object.cpp @@ -0,0 +1,50 @@ +/* + * Temporary file + * + * Authors: + * Adrian Boguszewski + * + * Copyright (C) 2016 Adrian Boguszewski + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "object.h" + +Object::Object(std::string name) : name(name), parent(NULL) { } + +Object::~Object() { + // only for this prototype + // call destructor on every child + children.clear_and_dispose(delete_disposer()); + release_signal.emit(this); +} + +const std::string& Object::getName() const { + return name; +} + +Object *Object::getParent() { + return parent; +} + +bool Object::isDescendantOf(Object *o) { + Object* p = parent; + while(p != NULL) { + if (p == o) { + return true; + } + p = p->parent; + } + return false; +} + +void Object::addChild(Object* o) { + o->parent = this; + children.push_back(*o); +} + +sigc::connection Object::connectRelease(sigc::slot slot) { + return release_signal.connect(slot); +} + diff --git a/src/object.h b/src/object.h new file mode 100644 index 000000000..a5ad5692e --- /dev/null +++ b/src/object.h @@ -0,0 +1,76 @@ +/* + * Temporary file + * + * Authors: + * Adrian Boguszewski + * + * Copyright (C) 2016 Adrian Boguszewski + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef INKSCAPE_PROTOTYPE_OBJECT_H +#define INKSCAPE_PROTOTYPE_OBJECT_H + +#include +#include +#include +#include + +// this causes some warning, but it's only for this prototype +class Object; +struct delete_disposer +{ + void operator()(Object *delete_this) { + delete delete_this; + } +}; + +class Object { +private: + std::string name; + Object* parent; + + typedef boost::intrusive::list_member_hook< + boost::intrusive::link_mode< + boost::intrusive::auto_unlink + >> list_hook; + list_hook child_hook; + + typedef boost::intrusive::list< + Object, + boost::intrusive::constant_time_size, + boost::intrusive::member_hook< + Object, + list_hook, + &Object::child_hook + >> list; + list children; + + sigc::signal release_signal; + +public: + Object(std::string name); + virtual ~Object(); + + list &getChildren() { + return children; + } + + const std::string &getName() const; + Object * getParent() ; + + sigc::connection connectRelease(sigc::slot slot); + void addChild(Object* o); + bool isDescendantOf(Object* o); + + bool operator==(Object o) { + return name == o.name; + } + + bool operator!=(Object o) { + return name != o.name; + } +}; + +#endif //INKSCAPE_PROTOTYPE_OBJECT_H -- cgit v1.2.3 From 8970301df8e29722a113e20295239c64e070d0d7 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Mon, 6 Jun 2016 22:50:06 +0530 Subject: Set class attribute values of selected objects using style dialog (bzr r14949.1.3) --- src/ui/dialog/styledialog.cpp | 71 +++++++++++++++++++++++++++++++++++++++++-- src/ui/dialog/styledialog.h | 1 + 2 files changed, 70 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 7e555ddb2..6681a7c56 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -1,3 +1,14 @@ +/** @file + * @brief A dialog for CSS selectors + */ +/* Authors: + * Kamalpreet Kaur Grewal + * + * Copyright (C) Kamalpreet Kaur Grewal 2016 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + #include "styledialog.h" #include "widgets/icon.h" #include "verbs.h" @@ -8,6 +19,13 @@ namespace Inkscape { namespace UI { namespace Dialog { +/** + * @brief StyleDialog::_styleButton + * @param btn + * @param iconName + * @param tooltip + * This function sets the style of '+' and '-' buttons at the bottom of dialog. + */ void StyleDialog::_styleButton(Gtk::Button& btn, char const* iconName, char const* tooltip) { @@ -68,6 +86,11 @@ void StyleDialog::setDesktop( SPDesktop* desktop ) _desktop = Panel::getDesktop(); } +/** + * @brief StyleDialog::_addSelector + * This function is the slot to the signal emitted when '+' at the bottom of + * the dialog is clicked. + */ void StyleDialog::_addSelector() { Gtk::TreeModel::Row row = *(_store->append()); @@ -81,7 +104,18 @@ void StyleDialog::_addSelector() Gtk::Entry *textEditPtr = manage ( new Gtk::Entry() ); textDialogPtr->add_button("Add", Gtk::RESPONSE_OK); textDialogPtr->get_vbox()->pack_start(*textEditPtr, Gtk::PACK_SHRINK); - textEditPtr->set_text("Class1"); + + /** + * By default, the entrybox contains 'Class1' as text. However, if object(s) + * is(are) selected and user clicks '+' at the bottom of dialog, the + * entrybox will have the id(s) of the selected objects as text. + */ + if (_desktop->selection->isEmpty()) + textEditPtr->set_text("Class1"); + else { + std::vector selected = _desktop->getSelection()->list(); + textEditPtr->set_text(_setClassAttribute(selected)); + } textDialogPtr->set_size_request(200, 100); textDialogPtr->show_all(); @@ -99,15 +133,48 @@ void StyleDialog::_addSelector() break; } + /** + * The 'class' attribute of the selected objects is set to the text that + * the user sets in the entrybox. If the attribute does not exist, it is + * created. In case the attribute already has a value, the new value entered + * is appended to the values. + */ if (_desktop->selection) { std::vector selected = _desktop->getSelection()->list(); for (int i = 0; i < selected.size(); ++i ) { SPObject *obj = selected.at(i); - obj->setAttribute("class", textEditPtr->get_text()); + const char *classExists = obj->getAttribute("class"); + + if (classExists) { + if (strlen(classExists) == 0) + obj->setAttribute("class", textEditPtr->get_text()); + else + obj->setAttribute("class", std::string(classExists) + " " + + textEditPtr->get_text()); + } + else { + obj->setAttribute("class", textEditPtr->get_text()); + } } } } +/** + * @brief StyleDialog::_setClassAttribute + * @param sel + * @return This function returns the ids of objects selected which are passed + * to entrybox. + */ +std::string StyleDialog::_setClassAttribute(std::vector sel) +{ + std::string str = ""; + for (int i = 0; i < sel.size(); ++i ) { + SPObject *obj = sel.at(i); + str = str + " " + std::string(obj->getId()); + } + return str; +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 044737add..281585d9d 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -40,6 +40,7 @@ public: private: void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); + std::string _setClassAttribute(std::vector); class ModelColumns : public Gtk::TreeModel::ColumnRecord { -- cgit v1.2.3 From ac25f7827cc250eb47eedf1bd3aa5ec8438fc0e5 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Tue, 7 Jun 2016 01:35:26 +0200 Subject: Add measure Over Item by a vlada idea on IRC (bzr r14957.1.1) --- src/ui/tools/measure-tool.cpp | 112 ++++++++++++++++++++++++++++++++++++++++++ src/ui/tools/measure-tool.h | 9 ++++ 2 files changed, 121 insertions(+) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 287828d32..8b2a734ff 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -394,6 +394,10 @@ MeasureTool::~MeasureTool() sp_canvas_item_destroy(measure_tmp_items[idx]); } measure_tmp_items.clear(); + for (size_t idx = 0; idx < measure_item.size(); ++idx) { + sp_canvas_item_destroy(measure_item[idx]); + } + measure_item.clear(); for (size_t idx = 0; idx < measure_phantom_items.size(); ++idx) { sp_canvas_item_destroy(measure_phantom_items[idx]); } @@ -608,6 +612,12 @@ bool MeasureTool::root_handler(GdkEvent* event) snap_manager.preSnap(scp); snap_manager.unSetup(); } + Geom::Point const motion_w(event->motion.x, event->motion.y); + if(event->motion.state & GDK_SHIFT_MASK) { + showInfoBox(motion_w, true); + } else { + showInfoBox(motion_w, false); + } } else { ret = TRUE; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -1128,6 +1138,108 @@ void MeasureTool::setMeasureCanvasControlLine(Geom::Point start, Geom::Point end } } +void MeasureTool::showItemInfoText(Geom::Point pos, gchar *measure_str, double fontsize) +{ + SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(), + desktop, + pos, + measure_str); + sp_canvastext_set_fontsize(canvas_tooltip, fontsize); + canvas_tooltip->rgba = 0xffffffff; + canvas_tooltip->outline = false; + canvas_tooltip->background = true; + canvas_tooltip->anchor_position = TEXT_ANCHOR_LEFT; + canvas_tooltip->rgba_background = 0x00000099; + measure_item.push_back(SP_CANVAS_ITEM(canvas_tooltip)); + sp_canvas_item_show(SP_CANVAS_ITEM(canvas_tooltip)); +} + +void MeasureTool::showInfoBox(Geom::Point cursor, bool into_groups) +{ + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + Inkscape::Util::Unit const * unit = desktop->getNamedView()->getDisplayUnit(); + for (size_t idx = 0; idx < measure_item.size(); ++idx) { + sp_canvas_item_destroy(measure_item[idx]); + } + measure_item.clear(); + + SPItem *newover = desktop->getItemAtPoint(cursor, into_groups); + if (newover) { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + double fontsize = prefs->getDouble("/tools/measure/fontsize", 10.0); + double scale = prefs->getDouble("/tools/measure/scale", 100.0) / 100.0; + int precision = prefs->getInt("/tools/measure/precision", 2); + Glib::ustring unit_name = prefs->getString("/tools/measure/unit"); + if (!unit_name.compare("")) { + unit_name = "px"; + } + Geom::Scale zoom = Geom::Scale(Inkscape::Util::Quantity::convert(desktop->current_zoom(), "px", unit->abbr)).inverse(); + if(newover != over){ + over = newover; + Preferences *prefs = Preferences::get(); + int prefs_bbox = prefs->getBool("/tools/bounding_box", 0); + SPItem::BBoxType bbox_type = !prefs_bbox ? SPItem::VISUAL_BBOX : SPItem::GEOMETRIC_BBOX; + Geom::OptRect bbox = over->bounds(bbox_type); + if (bbox) { + + item_width = Inkscape::Util::Quantity::convert((*bbox).width() * scale, unit->abbr, unit_name); + item_height = Inkscape::Util::Quantity::convert((*bbox).height() * scale, unit->abbr, unit_name); + item_x = Inkscape::Util::Quantity::convert((*bbox).left(), unit->abbr, unit_name); + Geom::Point y_point(0,Inkscape::Util::Quantity::convert((*bbox).bottom() * scale, unit->abbr, "px")); + y_point *= desktop->doc2dt(); + item_y = Inkscape::Util::Quantity::convert(y_point[Geom::Y] * scale, "px", unit_name); + if (SP_IS_SHAPE(over)) { + Geom::PathVector shape = SP_SHAPE(over)->getCurve()->get_pathvector(); + item_length = Geom::length(paths_to_pw(shape)); + item_length = Inkscape::Util::Quantity::convert(item_length * scale, unit->abbr, unit_name); + } + } + } + gchar *measure_str = NULL; + std::stringstream precision_str; + precision_str.imbue(std::locale::classic()); + double origin = Inkscape::Util::Quantity::convert(14, "px", unit->abbr); + Geom::Point rel_position = Geom::Point(origin, origin); + Geom::Point pos = desktop->w2d(cursor); + double gap = Inkscape::Util::Quantity::convert(7 + fontsize, "px", unit->abbr); + if (SP_IS_SHAPE(over)) { + precision_str << _("Lenght") << ": %." << precision << "f %s"; + measure_str = g_strdup_printf(precision_str.str().c_str(), item_length, unit_name.c_str()); + precision_str.str(""); + showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); + rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap); + } else if (SP_IS_GROUP(over)) { + measure_str = _("Shift to measure into group"); + showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); + rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap); + } + + precision_str << "Y: %." << precision << "f %s"; + measure_str = g_strdup_printf(precision_str.str().c_str(), item_y, unit_name.c_str()); + precision_str.str(""); + showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); + rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap); + + precision_str << "X: %." << precision << "f %s"; + measure_str = g_strdup_printf(precision_str.str().c_str(), item_x, unit_name.c_str()); + precision_str.str(""); + showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); + rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap); + + precision_str << _("Height") << ": %." << precision << "f %s"; + measure_str = g_strdup_printf(precision_str.str().c_str(), item_height, unit_name.c_str()); + precision_str.str(""); + showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); + rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap); + + precision_str << _("Width") << ": %." << precision << "f %s"; + measure_str = g_strdup_printf(precision_str.str().c_str(), item_width, unit_name.c_str()); + precision_str.str(""); + showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); + g_free(measure_str); + } +} + void MeasureTool::showCanvasItems(bool to_guides, bool to_item, bool to_phantom, Inkscape::XML::Node *measure_repr) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h index 14fc9f81a..42122dca1 100644 --- a/src/ui/tools/measure-tool.h +++ b/src/ui/tools/measure-tool.h @@ -54,6 +54,8 @@ public: virtual void setMarker(bool isStart); virtual const std::string& getPrefsPath(); Geom::Point readMeasurePoint(bool is_start); + void showInfoBox(Geom::Point cursor, bool into_groups); + void showItemInfoText(Geom::Point pos, gchar *measure_str, double fontsize); void writeMeasurePoint(Geom::Point point, bool is_start); void setGuide(Geom::Point origin, double angle, const char *label); void setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr); @@ -77,6 +79,13 @@ private: Geom::Point end_p; std::vector measure_tmp_items; std::vector measure_phantom_items; + std::vector measure_item; + double item_width; + double item_height; + double item_x; + double item_y; + double item_length; + SPItem *over; sigc::connection _knot_start_moved_connection; sigc::connection _knot_start_ungrabbed_connection; sigc::connection _knot_start_click_connection; -- cgit v1.2.3 From 5633812ca77f35e52db62e7b432761e0e59253fe Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 9 Jun 2016 17:19:23 +0200 Subject: Removed Object class and temporary test dependencies (bzr r14954.1.4) --- src/CMakeLists.txt | 2 -- src/object.cpp | 50 ----------------------------------- src/object.h | 76 ------------------------------------------------------ src/sp-flowtext.h | 1 + 4 files changed, 1 insertion(+), 128 deletions(-) delete mode 100644 src/object.cpp delete mode 100644 src/object.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 802a79c4f..92436ea9a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -229,7 +229,6 @@ set(inkscape_SRC message-context.cpp message-stack.cpp mod360.cpp - object.cpp object-hierarchy.cpp object-set.cpp object-snapper.cpp @@ -355,7 +354,6 @@ set(inkscape_SRC mod360-test.h mod360.h number-opt-number.h - object.h object-hierarchy.h object-set.h object-snapper.h diff --git a/src/object.cpp b/src/object.cpp deleted file mode 100644 index c05d50b3a..000000000 --- a/src/object.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Temporary file - * - * Authors: - * Adrian Boguszewski - * - * Copyright (C) 2016 Adrian Boguszewski - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "object.h" - -Object::Object(std::string name) : name(name), parent(NULL) { } - -Object::~Object() { - // only for this prototype - // call destructor on every child - children.clear_and_dispose(delete_disposer()); - release_signal.emit(this); -} - -const std::string& Object::getName() const { - return name; -} - -Object *Object::getParent() { - return parent; -} - -bool Object::isDescendantOf(Object *o) { - Object* p = parent; - while(p != NULL) { - if (p == o) { - return true; - } - p = p->parent; - } - return false; -} - -void Object::addChild(Object* o) { - o->parent = this; - children.push_back(*o); -} - -sigc::connection Object::connectRelease(sigc::slot slot) { - return release_signal.connect(slot); -} - diff --git a/src/object.h b/src/object.h deleted file mode 100644 index a5ad5692e..000000000 --- a/src/object.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Temporary file - * - * Authors: - * Adrian Boguszewski - * - * Copyright (C) 2016 Adrian Boguszewski - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef INKSCAPE_PROTOTYPE_OBJECT_H -#define INKSCAPE_PROTOTYPE_OBJECT_H - -#include -#include -#include -#include - -// this causes some warning, but it's only for this prototype -class Object; -struct delete_disposer -{ - void operator()(Object *delete_this) { - delete delete_this; - } -}; - -class Object { -private: - std::string name; - Object* parent; - - typedef boost::intrusive::list_member_hook< - boost::intrusive::link_mode< - boost::intrusive::auto_unlink - >> list_hook; - list_hook child_hook; - - typedef boost::intrusive::list< - Object, - boost::intrusive::constant_time_size, - boost::intrusive::member_hook< - Object, - list_hook, - &Object::child_hook - >> list; - list children; - - sigc::signal release_signal; - -public: - Object(std::string name); - virtual ~Object(); - - list &getChildren() { - return children; - } - - const std::string &getName() const; - Object * getParent() ; - - sigc::connection connectRelease(sigc::slot slot); - void addChild(Object* o); - bool isDescendantOf(Object* o); - - bool operator==(Object o) { - return name == o.name; - } - - bool operator!=(Object o) { - return name != o.name; - } -}; - -#endif //INKSCAPE_PROTOTYPE_OBJECT_H diff --git a/src/sp-flowtext.h b/src/sp-flowtext.h index 9ee676893..d0b0a19a4 100644 --- a/src/sp-flowtext.h +++ b/src/sp-flowtext.h @@ -8,6 +8,7 @@ #include "libnrtype/Layout-TNG.h" #include "sp-item.h" +#include "desktop.h" #define SP_FLOWTEXT(obj) (dynamic_cast((SPObject*)obj)) #define SP_IS_FLOWTEXT(obj) (dynamic_cast((SPObject*)obj) != NULL) -- cgit v1.2.3 From d05e7ac156a8dedc0e80390a80edaa90b6260a4c Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 10 Jun 2016 14:10:53 +0530 Subject: Add selector to style element (bzr r14949.1.5) --- src/ui/dialog/styledialog.cpp | 100 +++++++++++++++++++++++++++++++++--------- src/ui/dialog/styledialog.h | 2 + 2 files changed, 81 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 6681a7c56..992e75285 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -14,6 +14,10 @@ #include "verbs.h" #include "sp-object.h" #include "selection.h" +#include "xml/attribute-record.h" + +using Inkscape::Util::List; +using Inkscape::XML::AttributeRecord; namespace Inkscape { namespace UI { @@ -97,8 +101,8 @@ void StyleDialog::_addSelector() /** * On clicking '+' button, an entrybox with default text opens up. If an - * object is already selected, 'class' attribute with value in the entry - * is added to the selected object. + * object is already selected, a selector with value in the entry + * is added to a new style element. */ Gtk::Dialog *textDialogPtr = new Gtk::Dialog(); Gtk::Entry *textEditPtr = manage ( new Gtk::Entry() ); @@ -110,7 +114,7 @@ void StyleDialog::_addSelector() * is(are) selected and user clicks '+' at the bottom of dialog, the * entrybox will have the id(s) of the selected objects as text. */ - if (_desktop->selection->isEmpty()) + if ( _desktop->selection->isEmpty() ) textEditPtr->set_text("Class1"); else { std::vector selected = _desktop->getSelection()->list(); @@ -120,13 +124,28 @@ void StyleDialog::_addSelector() textDialogPtr->set_size_request(200, 100); textDialogPtr->show_all(); int result = textDialogPtr->run(); + + /** + * @brief selectorName + * This string stores selector name. If '#' or a '.' is present in the + * beginning of string, text from entrybox is saved directly as name for + * selector. If text like 'red' is written in entrybox, it is prefixed + * with a dot. + */ + std::string selectorName = ""; + if ( textEditPtr->get_text().at(0) == '#' || + textEditPtr->get_text().at(0) == '.' ) + selectorName = textEditPtr->get_text(); + else + selectorName = "." + textEditPtr->get_text(); + static int number = 1; switch (result) { case Gtk::RESPONSE_OK: textDialogPtr->hide(); row[_mColumns._selectorNumber] = number; - row[_mColumns._selectorLabel] = textEditPtr->get_text(); + row[_mColumns._selectorLabel] = selectorName; number++; break; default: @@ -134,27 +153,49 @@ void StyleDialog::_addSelector() } /** - * The 'class' attribute of the selected objects is set to the text that - * the user sets in the entrybox. If the attribute does not exist, it is + * The selector name objects is set to the text that the user sets in the + * entrybox. If the attribute does not exist, it is * created. In case the attribute already has a value, the new value entered * is appended to the values. */ - if (_desktop->selection) { + if ( _desktop->selection ) { std::vector selected = _desktop->getSelection()->list(); - for (int i = 0; i < selected.size(); ++i ) { + std::string selectorValue; + for ( unsigned i = 0; i < selected.size(); ++i ) { SPObject *obj = selected.at(i); - const char *classExists = obj->getAttribute("class"); - - if (classExists) { - if (strlen(classExists) == 0) - obj->setAttribute("class", textEditPtr->get_text()); - else - obj->setAttribute("class", std::string(classExists) + " " + - textEditPtr->get_text()); - } - else { - obj->setAttribute("class", textEditPtr->get_text()); + + std::string style = std::string(obj->getRepr()->attribute("style")); + style = row[_mColumns._selectorLabel] + ";" + style; + + for ( List iter = obj->getRepr()->attributeList() ; + iter ; ++iter ) { + gchar const * property = g_quark_to_string(iter->key); + gchar const * value = iter->value; + + if ( std::string(property) == "style" ) + { + selectorValue = row[_mColumns._selectorLabel] + "{" + + "\n" + std::string(value) + "\n" + "}"; + } } + + /** + * @brief root + * A new style element is added to the document with value obtained + * from selectorValue above. + */ + Inkscape::XML::Node *root = obj->getRepr()->document()->root(); + Inkscape::XML::Node *newChild = obj->getRepr()->document() + ->createElement("svg:style"); + + Inkscape::XML::Node *smallChildren = obj->getRepr()->document() + ->createTextNode(selectorValue.c_str()); + + newChild->appendChild(smallChildren); + Inkscape::GC::release(smallChildren); + + root->addChild(newChild, NULL); + Inkscape::GC::release(newChild); } } } @@ -168,13 +209,30 @@ void StyleDialog::_addSelector() std::string StyleDialog::_setClassAttribute(std::vector sel) { std::string str = ""; - for (int i = 0; i < sel.size(); ++i ) { + for (unsigned i = 0; i < sel.size(); ++i) { SPObject *obj = sel.at(i); - str = str + " " + std::string(obj->getId()); + str = str + "#" + std::string(obj->getId()) + " "; } return str; } +/** + * @brief StyleDialog::_populateTree + * @param _selMap + * This function will populate the treeview with selectors available in the + * stylesheet. Not used yet. + */ +void StyleDialog::_populateTree(std::map _selMap) +{ + std::map _selectMap = _selMap; + + for(std::map::iterator it = _selectMap.begin(); + it != _selectMap.end(); ++it) { + Gtk::TreeModel::Row row = *(_store->append()); + row[_mColumns._selectorLabel] = it->first; + } +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 281585d9d..21c33ab6e 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -41,6 +41,8 @@ public: private: void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); std::string _setClassAttribute(std::vector); + std::map_selectorMap; + void _populateTree(std::map); class ModelColumns : public Gtk::TreeModel::ColumnRecord { -- cgit v1.2.3 From 0792b241079daea6c984d9fd6761b9bdfbe85455 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 10 Jun 2016 20:13:26 +0530 Subject: Populate style dialog with existing selectors in stylesheet (bzr r14949.1.7) --- src/ui/dialog/styledialog.cpp | 49 +++++++++++++++++++++++++++++++------------ src/ui/dialog/styledialog.h | 4 ++-- 2 files changed, 38 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 992e75285..7a3dfeaff 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -59,7 +59,6 @@ StyleDialog::StyleDialog() : _store = Gtk::ListStore::create(_mColumns); _treeView.set_model(_store); - _treeView.append_column("Selector Number", _mColumns._selectorNumber); _treeView.append_column("Selector Name", _mColumns._selectorLabel); Gtk::Button* create = manage( new Gtk::Button() ); @@ -77,6 +76,32 @@ StyleDialog::StyleDialog() : SPDesktop* targetDesktop = getDesktop(); setDesktop(targetDesktop); + + /** + * @brief document + * If an existing document is opened, its XML representation is obtained + * and if it contains any style element with a style selector, the selector + * name and its value is extracted and saved to a map. This map is then used + * to populate the treeview with the already existing selectors. + */ + SPDocument * document = targetDesktop->doc(); + unsigned num = document->getReprRoot()->childCount(); + + std::string key, value; + std::map selMap; + + for ( unsigned i = 0; i < num; ++i ) + { + if ( std::string(document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) + { + char *str = strdup(document->getReprRoot()->nthChild(i)->firstChild() + ->content()); + key = strtok(str, " "); + value = strtok(NULL, ""); + selMap[key] = value; + } + } + _populateTree(selMap); } StyleDialog::~StyleDialog() @@ -134,19 +159,15 @@ void StyleDialog::_addSelector() */ std::string selectorName = ""; if ( textEditPtr->get_text().at(0) == '#' || - textEditPtr->get_text().at(0) == '.' ) + textEditPtr->get_text().at(0) == '.' ) selectorName = textEditPtr->get_text(); else selectorName = "." + textEditPtr->get_text(); - static int number = 1; - switch (result) { case Gtk::RESPONSE_OK: textDialogPtr->hide(); - row[_mColumns._selectorNumber] = number; row[_mColumns._selectorLabel] = selectorName; - number++; break; default: break; @@ -167,8 +188,8 @@ void StyleDialog::_addSelector() std::string style = std::string(obj->getRepr()->attribute("style")); style = row[_mColumns._selectorLabel] + ";" + style; - for ( List iter = obj->getRepr()->attributeList() ; - iter ; ++iter ) { + for ( List iter = obj->getRepr()->attributeList(); + iter; ++iter ) { gchar const * property = g_quark_to_string(iter->key); gchar const * value = iter->value; @@ -196,6 +217,8 @@ void StyleDialog::_addSelector() root->addChild(newChild, NULL); Inkscape::GC::release(newChild); + + _selectorMap[selectorName] = selectorValue; } } } @@ -209,7 +232,7 @@ void StyleDialog::_addSelector() std::string StyleDialog::_setClassAttribute(std::vector sel) { std::string str = ""; - for (unsigned i = 0; i < sel.size(); ++i) { + for ( unsigned i = 0; i < sel.size(); ++i ) { SPObject *obj = sel.at(i); str = str + "#" + std::string(obj->getId()) + " "; } @@ -219,15 +242,15 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) /** * @brief StyleDialog::_populateTree * @param _selMap - * This function will populate the treeview with selectors available in the - * stylesheet. Not used yet. + * This function populates the treeview with selectors available in the + * stylesheet. */ void StyleDialog::_populateTree(std::map _selMap) { std::map _selectMap = _selMap; - for(std::map::iterator it = _selectMap.begin(); - it != _selectMap.end(); ++it) { + for( std::map::iterator it = _selectMap.begin(); + it != _selectMap.end(); ++it ) { Gtk::TreeModel::Row row = *(_store->append()); row[_mColumns._selectorLabel] = it->first; } diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 21c33ab6e..79ff41559 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -19,6 +19,7 @@ #include #include "desktop.h" +#include "document.h" namespace Inkscape { namespace UI { @@ -48,8 +49,7 @@ private: { public: ModelColumns() - { add(_selectorNumber); add(_selectorLabel); } - Gtk::TreeModelColumn _selectorNumber; + { add(_selectorLabel); } Gtk::TreeModelColumn _selectorLabel; }; -- cgit v1.2.3 From 3bbe3debb72ae45a17eaa0133f73d8bc37c55b7b Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sat, 11 Jun 2016 10:57:36 +0530 Subject: Apply patch for broken automake (bzr r14949.1.9) --- src/ui/dialog/Makefile_insert | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/ui/dialog/Makefile_insert b/src/ui/dialog/Makefile_insert index 71628973e..982908731 100644 --- a/src/ui/dialog/Makefile_insert +++ b/src/ui/dialog/Makefile_insert @@ -92,6 +92,8 @@ ink_common_sources += \ ui/dialog/print-colors-preview-dialog.h \ ui/dialog/spellcheck.cpp \ ui/dialog/spellcheck.h \ + ui/dialog/styledialog.cpp \ + ui/dialog/styledialog.h \ ui/dialog/svg-fonts-dialog.cpp \ ui/dialog/svg-fonts-dialog.h \ ui/dialog/swatches.cpp \ -- cgit v1.2.3 From 6d5d7e5421a5ac585814bde11866d796d81653cd Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 11 Jun 2016 14:04:09 +0200 Subject: Fix a typo pointed by CR (bzr r14957.1.2) --- src/ui/tools/measure-tool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 8b2a734ff..900274afc 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -1203,7 +1203,7 @@ void MeasureTool::showInfoBox(Geom::Point cursor, bool into_groups) Geom::Point pos = desktop->w2d(cursor); double gap = Inkscape::Util::Quantity::convert(7 + fontsize, "px", unit->abbr); if (SP_IS_SHAPE(over)) { - precision_str << _("Lenght") << ": %." << precision << "f %s"; + precision_str << _("Length") << ": %." << precision << "f %s"; measure_str = g_strdup_printf(precision_str.str().c_str(), item_length, unit_name.c_str()); precision_str.str(""); showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize); -- 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 2e2712f1a6f1b31b18b40f9cffc58c8ef7b9198e Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sat, 11 Jun 2016 23:46:45 +0530 Subject: Delete selector from style dialog (not from repr yet) (bzr r14949.1.12) --- src/ui/dialog/styledialog.cpp | 115 +++++++++++++++++++++++++++++++++--------- src/ui/dialog/styledialog.h | 7 +++ 2 files changed, 97 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 7a3dfeaff..14213f97d 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -61,47 +61,31 @@ StyleDialog::StyleDialog() : _treeView.set_model(_store); _treeView.append_column("Selector Name", _mColumns._selectorLabel); - Gtk::Button* create = manage( new Gtk::Button() ); + create = manage( new Gtk::Button() ); _styleButton(*create, "list-add", "Add a new CSS Selector"); create->signal_clicked().connect(sigc::mem_fun(*this, &StyleDialog::_addSelector)); - Gtk::Button* del = manage( new Gtk::Button() ); + del = manage( new Gtk::Button() ); _styleButton(*del, "list-remove", "Remove a CSS Selector"); + del->signal_clicked().connect(sigc::mem_fun(*this, + &StyleDialog::_delSelector)); del->set_sensitive(false); _mainBox.pack_start(_buttonBox, Gtk::PACK_SHRINK); _buttonBox.pack_start(*create, Gtk::PACK_SHRINK); _buttonBox.pack_start(*del, Gtk::PACK_SHRINK); - SPDesktop* targetDesktop = getDesktop(); - setDesktop(targetDesktop); + _targetDesktop = getDesktop(); + setDesktop(_targetDesktop); /** * @brief document * If an existing document is opened, its XML representation is obtained - * and if it contains any style element with a style selector, the selector - * name and its value is extracted and saved to a map. This map is then used - * to populate the treeview with the already existing selectors. + * and is then used to populate the treeview with the already existing + * selectors in the style element. */ - SPDocument * document = targetDesktop->doc(); - unsigned num = document->getReprRoot()->childCount(); - - std::string key, value; - std::map selMap; - - for ( unsigned i = 0; i < num; ++i ) - { - if ( std::string(document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) - { - char *str = strdup(document->getReprRoot()->nthChild(i)->firstChild() - ->content()); - key = strtok(str, " "); - value = strtok(NULL, ""); - selMap[key] = value; - } - } - _populateTree(selMap); + _populateTree(_getSelectorMap()); } StyleDialog::~StyleDialog() @@ -173,6 +157,8 @@ void StyleDialog::_addSelector() break; } + del->set_sensitive(true); + /** * The selector name objects is set to the text that the user sets in the * entrybox. If the attribute does not exist, it is @@ -223,6 +209,52 @@ void StyleDialog::_addSelector() } } +/** + * @brief StyleDialog::_delSelector + * This function deletes selector when '-' at the bottom is clicked. Currently + * selectors are deleted from StyleDialog and not from repr of the document. + */ +void StyleDialog::_delSelector() +{ + Glib::RefPtr refTreeSelection = _treeView.get_selection(); + Gtk::TreeModel::iterator iter = refTreeSelection->get_selected(); + std::mapselMap = _getSelectorMap(); + + if (iter) + { + Gtk::TreeModel::Row row = *iter; + for( unsigned it = 0; it < selMap.size(); ++it ) { + std::string key = strtok(strdup(_document->getReprRoot() + ->nthChild(it) + ->firstChild()->content()), " "); + + /** + * @brief toDeleteNode + * The node to be deleted is obtained using nthChild and the selector + * name and corresponding style node from the repr of document are + * saved to a map. Keys of this map and labels of selected rows of + * dialog are compared and deleted. + */ + Inkscape::XML::Node *toDeleteNode = _document->getReprRoot()->nthChild(it); + std::maptoDeleteMap; + toDeleteMap[key] = toDeleteNode; + + for( std::map::iterator i = + toDeleteMap.begin(); i != toDeleteMap.end(); ++i ) { + if( row[_mColumns._selectorLabel] == i->first) + { + std::cout << i->second->name() << std::endl; + /** + This should work but uncommenting it causes a crash currently. + */ + //_document->getReprRoot()->removeChild(toDeleteNode); + } + } + } + _store->erase(row); + } +} + /** * @brief StyleDialog::_setClassAttribute * @param sel @@ -239,6 +271,36 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) return str; } +/** + * @brief StyleDialog::_getSelectorMap + * @return selMap + * This function returns a map whose key is the style selector name and value is + * the style properties. All style selectors are extracted from svg:style + * element. + */ +std::mapStyleDialog::_getSelectorMap() +{ + _document = _targetDesktop->doc(); + unsigned num = _document->getReprRoot()->childCount(); + + std::string key, value; + std::map selMap; + + for ( unsigned i = 0; i < num; ++i ) + { + if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) + { + char *str = strdup(_document->getReprRoot()->nthChild(i)->firstChild() + ->content()); + key = strtok(str, " "); + value = strtok(NULL, ""); + selMap[key] = value; + } + } + + return selMap; +} + /** * @brief StyleDialog::_populateTree * @param _selMap @@ -254,6 +316,9 @@ void StyleDialog::_populateTree(std::map _selMap) Gtk::TreeModel::Row row = *(_store->append()); row[_mColumns._selectorLabel] = it->first; } + + if (_selectMap.size() > 0) + del->set_sensitive(true); } } // namespace Dialog diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 79ff41559..f206b1e23 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -17,6 +17,7 @@ #include #include #include +#include #include "desktop.h" #include "document.h" @@ -43,6 +44,7 @@ private: void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); std::string _setClassAttribute(std::vector); std::map_selectorMap; + std::map _getSelectorMap(); void _populateTree(std::map); class ModelColumns : public Gtk::TreeModel::ColumnRecord @@ -54,15 +56,20 @@ private: }; SPDesktop* _desktop; + SPDesktop* _targetDesktop; ModelColumns _mColumns; Gtk::VBox _mainBox; Gtk::HBox _buttonBox; Gtk::TreeView _treeView; Glib::RefPtr _store; Gtk::ScrolledWindow _scrolledWindow; + Gtk::Button* del; + Gtk::Button* create; + SPDocument* _document; // Signal handlers void _addSelector(); + void _delSelector(); }; } // namespace Dialog -- 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 edc19028160caa0d92b943232483ba76fa8ea75b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 12 Jun 2016 18:27:42 +0200 Subject: Fix bug 'Persistent measure repositions on middle click' Fixed bugs: - https://launchpad.net/bugs/1591662 (bzr r14982) --- src/ui/tools/measure-tool.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 5900a2359..0977729ae 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -565,7 +565,6 @@ bool MeasureTool::root_handler(GdkEvent* event) explicit_base = boost::none; explicit_base_tmp = boost::none; last_end = boost::none; - start_p = desktop->w2d(button_w); if (event->button.button == 1 && !this->space_panning) { // save drag origin -- cgit v1.2.3 From 51cd1dfb720642e51b811558ddead6cd47ceee0f Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 12 Jun 2016 20:08:22 +0200 Subject: Fix faulty comparison function. (bzr r14983) --- src/attribute-sort-util.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/attribute-sort-util.cpp b/src/attribute-sort-util.cpp index ef08a142f..d0f45c418 100644 --- a/src/attribute-sort-util.cpp +++ b/src/attribute-sort-util.cpp @@ -65,9 +65,11 @@ void sp_attribute_sort_recursive(Node *repr) { */ bool cmp(std::pair< Glib::ustring, Glib::ustring > const &a, std::pair< Glib::ustring, Glib::ustring > const &b) { + unsigned val_a = sp_attribute_lookup(a.first.c_str()); unsigned val_b = sp_attribute_lookup(b.first.c_str()); - if (val_b == 0) return true; // Unknown attributes at end. - return sp_attribute_lookup(a.first.c_str()) < val_b; + if (val_a == 0) return false; // Unknown attributes at end. + if (val_b == 0) return true; // Unknown attributes at end. + return val_a < val_b; } /** -- cgit v1.2.3 From 35fc5dc7a7667ad3e79b409fb588c1cc56e2ab57 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 13 Jun 2016 00:10:49 +0200 Subject: Fix a helper path data (bzr r14984) --- src/live_effects/lpe-transform_2pts.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 1cd59b7fa..3c4ce0708 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -434,7 +434,7 @@ LPETransform2Pts::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector< } if(!lock_angle && lock_lenght) { char const * svgd; - svgd = "m 7.07,7.07 c -3.9,3.91 -10.24,3.91 -14.14,0 -3.91,-3.9 -3.91,-10.24 0,-14.14 3.9,-3.91 10.24,-3.91 14.14,0 l -2.83,-4.24 -0.7,2.12"; + svgd = "M 0,9.94 C -2.56,9.91 -5.17,8.98 -7.07,7.07 c -3.91,-3.9 -3.91,-10.24 0,-14.14 1.97,-1.97 4.51,-3.02 7.07,-3.04 2.56,0.02 5.1,1.07 7.07,3.04 3.91,3.9 3.91,10.24 0,14.14 C 5.17,8.98 2.56,9.91 0,9.94 Z"; PathVector pathv_turn = sp_svg_read_pathv(svgd); pathv_turn *= Geom::Rotate(previous_angle); pathv_turn *= Affine(r,0,0,r,0,0) * Translate(Geom::Point(end)); -- cgit v1.2.3 From 73f078b27b669c941651ecf14a3119ae491ccabf Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 13 Jun 2016 00:58:55 +0200 Subject: Fix 90% of tweenk review (bzr r13645.1.155) --- src/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 b9f56542de1f33e8ac45325653dcac11691e3e47 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Mon, 13 Jun 2016 12:27:11 +0530 Subject: Correct parsing of style element (bzr r14949.1.14) --- src/ui/dialog/styledialog.cpp | 67 ++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 14213f97d..9abcc1562 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -19,6 +19,8 @@ using Inkscape::Util::List; using Inkscape::XML::AttributeRecord; +#define REMOVE_SPACES(x) x.erase(std::remove(x.begin(), x.end(), ' '), x.end()); + namespace Inkscape { namespace UI { namespace Dialog { @@ -181,8 +183,8 @@ void StyleDialog::_addSelector() if ( std::string(property) == "style" ) { - selectorValue = row[_mColumns._selectorLabel] + "{" + - "\n" + std::string(value) + "\n" + "}"; + selectorValue = "\n" + row[_mColumns._selectorLabel] + "{" + + std::string(value) + "}"; } } @@ -223,10 +225,10 @@ void StyleDialog::_delSelector() if (iter) { Gtk::TreeModel::Row row = *iter; - for( unsigned it = 0; it < selMap.size(); ++it ) { - std::string key = strtok(strdup(_document->getReprRoot() - ->nthChild(it) - ->firstChild()->content()), " "); +// for( unsigned it = 0; it < selMap.size(); ++it ) { +// std::string key = strtok(strdup(_document->getReprRoot() +// ->nthChild(it) +// ->firstChild()->content()), "{"); /** * @brief toDeleteNode @@ -235,22 +237,22 @@ void StyleDialog::_delSelector() * saved to a map. Keys of this map and labels of selected rows of * dialog are compared and deleted. */ - Inkscape::XML::Node *toDeleteNode = _document->getReprRoot()->nthChild(it); - std::maptoDeleteMap; - toDeleteMap[key] = toDeleteNode; - - for( std::map::iterator i = - toDeleteMap.begin(); i != toDeleteMap.end(); ++i ) { - if( row[_mColumns._selectorLabel] == i->first) - { - std::cout << i->second->name() << std::endl; - /** - This should work but uncommenting it causes a crash currently. - */ - //_document->getReprRoot()->removeChild(toDeleteNode); - } - } - } +// Inkscape::XML::Node *toDeleteNode = _document->getReprRoot()->nthChild(it); +// std::maptoDeleteMap; +// toDeleteMap[key] = toDeleteNode; + +// for( std::map::iterator i = +// toDeleteMap.begin(); i != toDeleteMap.end(); ++i ) { +// if( row[_mColumns._selectorLabel] == i->first) +// { +// std::cout << i->second->name() << std::endl; +// /** +// This should work but uncommenting it causes a crash currently. +// */ +// //_document->getReprRoot()->removeChild(toDeleteNode); +// } +// } +// } _store->erase(row); } } @@ -290,11 +292,22 @@ std::mapStyleDialog::_getSelectorMap() { if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) { - char *str = strdup(_document->getReprRoot()->nthChild(i)->firstChild() - ->content()); - key = strtok(str, " "); - value = strtok(NULL, ""); - selMap[key] = value; + std::stringstream str; + str << _document->getReprRoot()->nthChild(i)->firstChild()->content(); + std::string sel; + + while (str != NULL) + { + while(std::getline(str, sel, '\n')){ + REMOVE_SPACES(sel); + if (!sel.empty()) + { + key = strtok(strdup(sel.c_str()), "{"); + value = strtok(NULL, "}"); + selMap[key] = value; + } + } + } } } -- cgit v1.2.3 From d35fb3b6e570691908282543b97076591510c5f3 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Mon, 13 Jun 2016 13:31:06 +0530 Subject: Fix crash when object without style attribute is added to selector (bzr r14949.1.15) --- src/ui/dialog/styledialog.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 9abcc1562..997d8b230 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -173,21 +173,28 @@ void StyleDialog::_addSelector() for ( unsigned i = 0; i < selected.size(); ++i ) { SPObject *obj = selected.at(i); - std::string style = std::string(obj->getRepr()->attribute("style")); - style = row[_mColumns._selectorLabel] + ";" + style; - - for ( List iter = obj->getRepr()->attributeList(); - iter; ++iter ) { - gchar const * property = g_quark_to_string(iter->key); - gchar const * value = iter->value; - - if ( std::string(property) == "style" ) - { - selectorValue = "\n" + row[_mColumns._selectorLabel] + "{" - + std::string(value) + "}"; + if (obj->getRepr()->attribute("style")) + { + std::string style = std::string(obj->getRepr()->attribute("style")); + style = row[_mColumns._selectorLabel] + ";" + style; + + for ( List iter = obj->getRepr()->attributeList(); + iter; ++iter ) { + gchar const * property = g_quark_to_string(iter->key); + gchar const * value = iter->value; + + if ( std::string(property) == "style" ) + { + selectorValue = "\n" + row[_mColumns._selectorLabel] + "{" + + std::string(value) + "}"; + } } } + else + std::cout << "This object does not have a style attribute. Add " + "one first."; + /** * @brief root * A new style element is added to the document with value obtained -- cgit v1.2.3 From a2c9a2962f6b9d4419b689ed4924f2cae2485332 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Mon, 13 Jun 2016 18:43:40 +0530 Subject: Set style and class attribute of object approprialtely when adding new style selector (bzr r14949.1.16) --- src/ui/dialog/styledialog.cpp | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 997d8b230..15c870e5d 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -165,17 +165,20 @@ void StyleDialog::_addSelector() * The selector name objects is set to the text that the user sets in the * entrybox. If the attribute does not exist, it is * created. In case the attribute already has a value, the new value entered - * is appended to the values. + * is appended to the values. If a style attribute does not exist, it is + * created with an empty value. Also if a class selector is added, then + * class attribute for the selected object is set too. */ if ( _desktop->selection ) { std::vector selected = _desktop->getSelection()->list(); std::string selectorValue; for ( unsigned i = 0; i < selected.size(); ++i ) { SPObject *obj = selected.at(i); + std::string style; if (obj->getRepr()->attribute("style")) { - std::string style = std::string(obj->getRepr()->attribute("style")); + style = std::string(obj->getRepr()->attribute("style")); style = row[_mColumns._selectorLabel] + ";" + style; for ( List iter = obj->getRepr()->attributeList(); @@ -192,8 +195,23 @@ void StyleDialog::_addSelector() } else - std::cout << "This object does not have a style attribute. Add " - "one first."; + { + style = " "; + std::cout << "style" << style; + obj->getRepr()->setAttribute("style", style); + } + + if ( strcmp(selectorName.substr(0,1).c_str(), ".") == 0 ){ + if (!obj->getRepr()->attribute("class")) + obj->getRepr()->setAttribute("class", textEditPtr->get_text() + .erase(0,1)); + else + obj->getRepr()->setAttribute("class", std::string(obj-> + getRepr()-> + attribute("class")) + + " " + textEditPtr->get_text() + .erase(0,0)); + } /** * @brief root @@ -303,16 +321,13 @@ std::mapStyleDialog::_getSelectorMap() str << _document->getReprRoot()->nthChild(i)->firstChild()->content(); std::string sel; - while (str != NULL) - { - while(std::getline(str, sel, '\n')){ - REMOVE_SPACES(sel); - if (!sel.empty()) - { - key = strtok(strdup(sel.c_str()), "{"); - value = strtok(NULL, "}"); - selMap[key] = value; - } + while(std::getline(str, sel, '\n')){ + REMOVE_SPACES(sel); + if (!sel.empty()) + { + key = strtok(strdup(sel.c_str()), "{"); + value = strtok(NULL, "}"); + selMap[key] = value; } } } -- cgit v1.2.3 From 3e173aedbe72ba21d33eaec804bf4c9f8e9fa158 Mon Sep 17 00:00:00 2001 From: brock-alexander Date: Tue, 14 Jun 2016 12:26:58 +0200 Subject: Merging lp:~inkscape+alexander/inkscape/comments into lp:inkscape. (bzr r14986) --- src/document.cpp | 22 ++++++++++++++++++++++ src/document.h | 2 +- src/sp-object.cpp | 15 ++++++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/document.cpp b/src/document.cpp index d8c3f1269..902dabbc3 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -1602,11 +1602,22 @@ static unsigned int count_objects_recursive(SPObject *obj, unsigned int count) return count; } +/** + * Count the number of objects in a given document recursively using the count_objects_recursive helper function + * + * @param[in] document Pointer to the document for counting objects + * @return Numer of objects in the document + */ static unsigned int objects_in_document(SPDocument *document) { return count_objects_recursive(document->getRoot(), 0); } +/** + * Remove unused definitions etc. recursively from an object and its siblings + * + * @param[inout] obj Object which shall be "cleaned" + */ static void vacuum_document_recursive(SPObject *obj) { if (SP_IS_DEFS(obj)) { @@ -1621,6 +1632,11 @@ static void vacuum_document_recursive(SPObject *obj) } } +/** + * Remove unused definitions etc. recursively from an entire document. + * + * @return Number of removed objects + */ unsigned int SPDocument::vacuumDocument() { unsigned int start = objects_in_document(this); @@ -1639,6 +1655,7 @@ unsigned int SPDocument::vacuumDocument() newend = objects_in_document(this); } while (iterations < 100 && newend < end); + // We stop if vacuum_document_recursive doesn't remove any more objects or after 100 iterations, whichever occurs first. return start - newend; } @@ -1647,6 +1664,11 @@ bool SPDocument::isSeeking() const { return priv->seeking; } +/** + * Indicate to the user if the document has been modified since the last save by displaying a "*" in front of the name of the file in the window title. + * + * @param[in] modified True if the document has been modified. + */ void SPDocument::setModifiedSinceSave(bool modified) { this->modified_since_save = modified; if (SP_ACTIVE_DESKTOP) { diff --git a/src/document.h b/src/document.h index e95042155..813d4ae49 100644 --- a/src/document.h +++ b/src/document.h @@ -198,7 +198,7 @@ public: bool isSeeking() const; bool isModifiedSinceSave() const { return modified_since_save; } - void setModifiedSinceSave(bool modified = true); + void setModifiedSinceSave(bool const modified = true); private: SPDocument(SPDocument const &); // no copy diff --git a/src/sp-object.cpp b/src/sp-object.cpp index db66eb3e6..d1659eedc 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -71,13 +71,17 @@ Inkscape::XML::NodeEventVector object_event_vector = { SPObject::repr_order_changed }; -// A friend class used to set internal members on SPObject so as to not expose settors in SPObject's public API +/** + * A friend class used to set internal members on SPObject so as to not expose settors in SPObject's public API + */ class SPObjectImpl { public: /** * Null's the id member of an SPObject without attempting to free prior contents. + * + * @param[inout] obj Pointer to the object which's id shall be nulled. */ static void setIdNull( SPObject* obj ) { if (obj) { @@ -87,6 +91,9 @@ public: /** * Sets the id member of an object, freeing any prior content. + * + * @param[inout] obj Pointer to the object which's id shall be set. + * @param[in] id New id */ static void setId( SPObject* obj, gchar const* id ) { if (obj && (id != obj->id) ) { @@ -104,6 +111,9 @@ public: static gchar *sp_object_get_unique_id(SPObject *object, gchar const *defid); +/** + * Constructor, sets all attributes to default values. + */ SPObject::SPObject() : cloned(0), uflags(0), mflags(0), hrefcount(0), _total_hrefcount(0), document(NULL), parent(NULL), children(NULL), _last_child(NULL), @@ -126,6 +136,9 @@ SPObject::SPObject() this->context_style = NULL; } +/** + * Destructor, frees the used memory and unreferences a potential successor of the object. + */ SPObject::~SPObject() { g_free(this->_label); g_free(this->_default_label); -- cgit v1.2.3 From 41c854edad820e281097f6ba8f17ea89521155ea Mon Sep 17 00:00:00 2001 From: Mark Harmer Date: Tue, 14 Jun 2016 14:33:17 +0200 Subject: [Bug #1300865] lcms2: crash in Fill and Stroke if linked color profile is missing on local system. Fixed bugs: - https://launchpad.net/bugs/1300865 (bzr r14987) --- src/color-profile.cpp | 6 +++++- src/ui/widget/color-icc-selector.cpp | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/color-profile.cpp b/src/color-profile.cpp index 9e545df03..aea9ccab0 100644 --- a/src/color-profile.cpp +++ b/src/color-profile.cpp @@ -588,7 +588,11 @@ bool ColorProfile::GamutCheck(SPColor color) static_cast(SP_RGBA32_G_U(val)), static_cast(SP_RGBA32_B_U(val)), 255}; - cmsDoTransform(ColorProfile::getTransfGamutCheck(), &check_color, &outofgamut, 1); + + cmsHTRANSFORM gamutCheck = ColorProfile::getTransfGamutCheck(); + if (gamutCheck) { + cmsDoTransform(gamutCheck, &check_color, &outofgamut, 1); + } #if HAVE_LIBLCMS1 cmsSetAlarmCodes(alarm_r, alarm_g, alarm_b); diff --git a/src/ui/widget/color-icc-selector.cpp b/src/ui/widget/color-icc-selector.cpp index b422892fe..e4f58fe8a 100644 --- a/src/ui/widget/color-icc-selector.cpp +++ b/src/ui/widget/color-icc-selector.cpp @@ -633,9 +633,10 @@ void ColorICCSelectorImpl::_switchToProfile(gchar const *name) #endif // DEBUG_LCMS tmp.set(SP_RGBA32_U_COMPOSE(pre[0], pre[1], pre[2], 0xff)); } + + dirty = true; } } - dirty = true; } } else { -- 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 cf648cc9b825188b3a790eeeb202b52b07ff6cef Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Wed, 15 Jun 2016 19:54:38 +0530 Subject: Add selector to single style element & replace storage map by a vector (bzr r14949.1.18) --- src/ui/dialog/styledialog.cpp | 106 +++++++++++++++++++++++++++--------------- src/ui/dialog/styledialog.h | 8 ++-- 2 files changed, 74 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 15c870e5d..bab08390c 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -10,6 +10,7 @@ */ #include "styledialog.h" +#include "ui/widget/addtoicon.h" #include "widgets/icon.h" #include "verbs.h" #include "sp-object.h" @@ -61,6 +62,11 @@ StyleDialog::StyleDialog() : _store = Gtk::ListStore::create(_mColumns); _treeView.set_model(_store); + + Inkscape::UI::Widget::AddToIcon * addRenderer = manage( + new Inkscape::UI::Widget::AddToIcon() ); + addRenderer->property_active() = true; + _treeView.append_column("type", *addRenderer); _treeView.append_column("Selector Name", _mColumns._selectorLabel); create = manage( new Gtk::Button() ); @@ -87,7 +93,8 @@ StyleDialog::StyleDialog() : * and is then used to populate the treeview with the already existing * selectors in the style element. */ - _populateTree(_getSelectorMap()); + _styleExists = false; + _sValue = _populateTree(_getSelectorVec()); } StyleDialog::~StyleDialog() @@ -178,9 +185,6 @@ void StyleDialog::_addSelector() if (obj->getRepr()->attribute("style")) { - style = std::string(obj->getRepr()->attribute("style")); - style = row[_mColumns._selectorLabel] + ";" + style; - for ( List iter = obj->getRepr()->attributeList(); iter; ++iter ) { gchar const * property = g_quark_to_string(iter->key); @@ -188,8 +192,8 @@ void StyleDialog::_addSelector() if ( std::string(property) == "style" ) { - selectorValue = "\n" + row[_mColumns._selectorLabel] + "{" - + std::string(value) + "}"; + selectorValue = row[_mColumns._selectorLabel] + "{" + + std::string(value) + "}" + "\n"; } } } @@ -197,7 +201,6 @@ void StyleDialog::_addSelector() else { style = " "; - std::cout << "style" << style; obj->getRepr()->setAttribute("style", style); } @@ -216,22 +219,45 @@ void StyleDialog::_addSelector() /** * @brief root * A new style element is added to the document with value obtained - * from selectorValue above. + * from selectorValue above. If style element already exists, then + * the new selector's content is appended to its previous content. */ - Inkscape::XML::Node *root = obj->getRepr()->document()->root(); - Inkscape::XML::Node *newChild = obj->getRepr()->document() - ->createElement("svg:style"); - - Inkscape::XML::Node *smallChildren = obj->getRepr()->document() - ->createTextNode(selectorValue.c_str()); - - newChild->appendChild(smallChildren); - Inkscape::GC::release(smallChildren); - - root->addChild(newChild, NULL); - Inkscape::GC::release(newChild); + unsigned num = _document->getReprRoot()->childCount(); + Inkscape::XML::Node *styleChild; + for ( unsigned i = 0; i < num; ++i ) + { + if ( std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style" ) + { + _styleExists = true; + styleChild = _document->getReprRoot()->nthChild(i); + break; + } + else + _styleExists = false; + } - _selectorMap[selectorName] = selectorValue; + if ( _styleExists ) + { + _sValue = _sValue + selectorValue; + styleChild->firstChild()->setContent(_sValue.c_str()); + } + else + { + _sValue = selectorValue; + Inkscape::XML::Node *root = obj->getRepr()->document()->root(); + Inkscape::XML::Node *newChild = obj->getRepr()->document() + ->createElement("svg:style"); + Inkscape::XML::Node *smallChildren = obj->getRepr()->document() + ->createTextNode(selectorValue.c_str()); + + newChild->appendChild(smallChildren); + Inkscape::GC::release(smallChildren); + + root->addChild(newChild, NULL); + Inkscape::GC::release(newChild); + } + _selectorVec.push_back(std::make_pair(selectorName, selectorValue)); } } } @@ -245,7 +271,7 @@ void StyleDialog::_delSelector() { Glib::RefPtr refTreeSelection = _treeView.get_selection(); Gtk::TreeModel::iterator iter = refTreeSelection->get_selected(); - std::mapselMap = _getSelectorMap(); + std::vector >selVec = _getSelectorVec(); if (iter) { @@ -299,19 +325,19 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) } /** - * @brief StyleDialog::_getSelectorMap - * @return selMap - * This function returns a map whose key is the style selector name and value is - * the style properties. All style selectors are extracted from svg:style + * @brief StyleDialog::_getSelectorVec + * @return selVec + * This function returns a vector whose key is the style selector name and value + * is the style properties. All style selectors are extracted from svg:style * element. */ -std::mapStyleDialog::_getSelectorMap() +std::vector >StyleDialog::_getSelectorVec() { _document = _targetDesktop->doc(); unsigned num = _document->getReprRoot()->childCount(); std::string key, value; - std::map selMap; + std::vector > selVec; for ( unsigned i = 0; i < num; ++i ) { @@ -327,33 +353,39 @@ std::mapStyleDialog::_getSelectorMap() { key = strtok(strdup(sel.c_str()), "{"); value = strtok(NULL, "}"); - selMap[key] = value; + selVec.push_back(std::make_pair(key, value)); } } } } - return selMap; + return selVec; } /** * @brief StyleDialog::_populateTree - * @param _selMap + * @param _selVec * This function populates the treeview with selectors available in the * stylesheet. */ -void StyleDialog::_populateTree(std::map _selMap) +std::string StyleDialog::_populateTree(std::vector > _selVec) { - std::map _selectMap = _selMap; + std::vector > _selectVec = _selVec; + std::string selectorValue; - for( std::map::iterator it = _selectMap.begin(); - it != _selectMap.end(); ++it ) { + for( unsigned it = 0; it < _selectVec.size(); ++it ) { Gtk::TreeModel::Row row = *(_store->append()); - row[_mColumns._selectorLabel] = it->first; + row[_mColumns._selectorLabel] = _selectVec[it].first; + std::string selValue = _selectVec[it].first + " { " + + _selectVec[it].second + " }" + "\n"; + selectorValue.append(selValue.c_str()); } - if (_selectMap.size() > 0) + if (_selectVec.size() > 0) del->set_sensitive(true); + + return selectorValue; } } // namespace Dialog diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index f206b1e23..0cba3bf5b 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -43,9 +43,9 @@ public: private: void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); std::string _setClassAttribute(std::vector); - std::map_selectorMap; - std::map _getSelectorMap(); - void _populateTree(std::map); + std::vector >_selectorVec; + std::vector > _getSelectorVec(); + std::string _populateTree(std::vector >); class ModelColumns : public Gtk::TreeModel::ColumnRecord { @@ -66,6 +66,8 @@ private: Gtk::Button* del; Gtk::Button* create; SPDocument* _document; + bool _styleExists; + std::string _sValue ; // Signal handlers void _addSelector(); -- cgit v1.2.3 From c21fa260cf5dde3e3558414ad69b05e04f173a73 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Thu, 16 Jun 2016 00:14:01 +0530 Subject: Implement deletion of style selector both from repr and treeview (bzr r14949.1.19) --- src/ui/dialog/styledialog.cpp | 70 ++++++++++++++++++++----------------------- src/ui/dialog/styledialog.h | 2 ++ 2 files changed, 34 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index bab08390c..a56277054 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -94,6 +94,8 @@ StyleDialog::StyleDialog() : * selectors in the style element. */ _styleExists = false; + _document = _targetDesktop->doc(); + _num = _document->getReprRoot()->childCount(); _sValue = _populateTree(_getSelectorVec()); } @@ -222,15 +224,13 @@ void StyleDialog::_addSelector() * from selectorValue above. If style element already exists, then * the new selector's content is appended to its previous content. */ - unsigned num = _document->getReprRoot()->childCount(); - Inkscape::XML::Node *styleChild; - for ( unsigned i = 0; i < num; ++i ) + for ( unsigned i = 0; i < _num; ++i ) { if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) { _styleExists = true; - styleChild = _document->getReprRoot()->nthChild(i); + _styleChild = _document->getReprRoot()->nthChild(i); break; } else @@ -240,7 +240,7 @@ void StyleDialog::_addSelector() if ( _styleExists ) { _sValue = _sValue + selectorValue; - styleChild->firstChild()->setContent(_sValue.c_str()); + _styleChild->firstChild()->setContent(_sValue.c_str()); } else { @@ -264,46 +264,34 @@ void StyleDialog::_addSelector() /** * @brief StyleDialog::_delSelector - * This function deletes selector when '-' at the bottom is clicked. Currently - * selectors are deleted from StyleDialog and not from repr of the document. + * This function deletes selector when '-' at the bottom is clicked. The index + * of selected row is obtained and the corresponding selector and its values are + * deleted from the selector vector. Then _sValue's content is reset and contains + * only selectors remaining in the selVec (or treeview). */ void StyleDialog::_delSelector() { Glib::RefPtr refTreeSelection = _treeView.get_selection(); Gtk::TreeModel::iterator iter = refTreeSelection->get_selected(); std::vector >selVec = _getSelectorVec(); + Gtk::TreeModel::Path path; if (iter) { Gtk::TreeModel::Row row = *iter; -// for( unsigned it = 0; it < selMap.size(); ++it ) { -// std::string key = strtok(strdup(_document->getReprRoot() -// ->nthChild(it) -// ->firstChild()->content()), "{"); + path = _treeView.get_model()->get_path(iter); + int i = atoi(path.to_string().c_str()); + selVec.erase(selVec.begin()+i); + _sValue.clear(); - /** - * @brief toDeleteNode - * The node to be deleted is obtained using nthChild and the selector - * name and corresponding style node from the repr of document are - * saved to a map. Keys of this map and labels of selected rows of - * dialog are compared and deleted. - */ -// Inkscape::XML::Node *toDeleteNode = _document->getReprRoot()->nthChild(it); -// std::maptoDeleteMap; -// toDeleteMap[key] = toDeleteNode; - -// for( std::map::iterator i = -// toDeleteMap.begin(); i != toDeleteMap.end(); ++i ) { -// if( row[_mColumns._selectorLabel] == i->first) -// { -// std::cout << i->second->name() << std::endl; -// /** -// This should work but uncommenting it causes a crash currently. -// */ -// //_document->getReprRoot()->removeChild(toDeleteNode); -// } -// } -// } + for (unsigned i = 0; i < selVec.size(); ++i) + { + std::string selValue = (selVec[i].first + "{" + + selVec[i].second + " }\n"); + _sValue.append(selValue.c_str()); + } + + _styleChild->firstChild()->setContent(_sValue.c_str()); _store->erase(row); } } @@ -333,13 +321,10 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) */ std::vector >StyleDialog::_getSelectorVec() { - _document = _targetDesktop->doc(); - unsigned num = _document->getReprRoot()->childCount(); - std::string key, value; std::vector > selVec; - for ( unsigned i = 0; i < num; ++i ) + for ( unsigned i = 0; i < _num; ++i ) { if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) { @@ -385,6 +370,15 @@ std::string StyleDialog::_populateTree(std::vector 0) del->set_sensitive(true); + for ( unsigned i = 0; i < _num; ++i ) + { + if ( std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style" ) + { + _styleChild = _document->getReprRoot()->nthChild(i); + } + } + return selectorValue; } diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 0cba3bf5b..502a7a3d4 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -68,6 +68,8 @@ private: SPDocument* _document; bool _styleExists; std::string _sValue ; + Inkscape::XML::Node *_styleChild; + unsigned _num; // Signal handlers void _addSelector(); -- cgit v1.2.3 From 425108aeb0731b11a5751b04f8e029b7a48ad0ab Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 16 Jun 2016 14:01:16 +0200 Subject: Fix z-cycling (alt+mousewheel) behavior Fixed bugs: - https://launchpad.net/bugs/1589420 (bzr r14988) --- src/ui/tools/select-tool.cpp | 199 ++++++++++++++++++------------------------- src/ui/tools/select-tool.h | 3 +- 2 files changed, 84 insertions(+), 118 deletions(-) (limited to 'src') diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index 905e38f2b..5b48d65be 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -111,7 +111,6 @@ SelectTool::SelectTool() //static gint tolerance = 0; //static bool within_tolerance = false; static bool is_cycling = false; -static bool moved_while_cycling = false; SelectTool::~SelectTool() { @@ -386,54 +385,68 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) { } void SelectTool::sp_select_context_cycle_through_items(Inkscape::Selection *selection, GdkEventScroll *scroll_event, bool shift_pressed) { - if (this->cycling_cur_item == this->cycling_items.end()) { + if ( this->cycling_items.empty() ) return; - } Inkscape::DrawingItem *arenaitem; - SPItem *item = *cycling_cur_item; - g_assert(item != NULL); - // Deactivate current item - if (std::find(cycling_items_selected_before.begin(), cycling_items_selected_before.end(), item) == cycling_items_selected_before.end() && selection->includes(item)) { - selection->remove(item); + if(cycling_cur_item) { + arenaitem = cycling_cur_item->get_arenaitem(desktop->dkey); + arenaitem->setOpacity(0.3); } - arenaitem = item->get_arenaitem(desktop->dkey); - arenaitem->setOpacity(0.3); - // Find next item and activate it - std::vector::iterator next = this->cycling_cur_item; + + + std::vector::iterator next = cycling_items.end(); + if (scroll_event->direction == GDK_SCROLL_UP) { - ++next; - if (next == this->cycling_items.end() && this->cycling_wrap) { - next = this->cycling_items.begin(); + if (! cycling_cur_item) { + next = cycling_items.begin(); + } else { + next = std::find( cycling_items.begin(), cycling_items.end(), cycling_cur_item ); + g_assert (next != cycling_items.end()); + next++; + if (next == cycling_items.end()) + if ( cycling_wrap ) + next = cycling_items.begin(); + else + next--; } - } else { - if(next == this->cycling_items.begin()) { - next = this->cycling_items.end(); + } else { + if (! cycling_cur_item) { + next = cycling_items.end(); + next--; + } else { + next = std::find( cycling_items.begin(), cycling_items.end(), cycling_cur_item ); + g_assert (next != cycling_items.end()); + if (next == cycling_items.begin()){ + if ( cycling_wrap ) { + next = cycling_items.end(); + next--; + } + } else { + next--; + } } - --next; } - if (next!=this->cycling_items.end()) { - this->cycling_cur_item = next; - item = *next; - g_assert(item != NULL); - } + this->cycling_cur_item = *next; + g_assert(next != cycling_items.end()); + g_assert(cycling_cur_item != NULL); - arenaitem = item->get_arenaitem(desktop->dkey); + arenaitem = cycling_cur_item->get_arenaitem(desktop->dkey); arenaitem->setOpacity(1.0); if (shift_pressed) { - selection->add(item); + selection->add(cycling_cur_item); } else { - selection->set(item); + selection->set(cycling_cur_item); } } void SelectTool::sp_select_context_reset_opacities() { - for (std::vector::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l ) { + for (std::vector::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l ) { SPItem *item = *l; if (item) { Inkscape::DrawingItem *arenaitem = item->get_arenaitem(desktop->dkey); @@ -443,10 +456,8 @@ void SelectTool::sp_select_context_reset_opacities() { } } - this->cycling_items.clear(); - this->cycling_items_selected_before.clear(); - this->cycling_cur_item = this->cycling_items.end(); this->cycling_items_cmp.clear(); + this->cycling_cur_item = NULL; } bool SelectTool::root_handler(GdkEvent* event) { @@ -533,11 +544,7 @@ bool SelectTool::root_handler(GdkEvent* event) { case GDK_MOTION_NOTIFY: { - if (is_cycling) { - moved_while_cycling = true; - } - - tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); + tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if ((event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) { Geom::Point const motion_pt(event->motion.x, event->motion.y); @@ -796,98 +803,58 @@ bool SelectTool::root_handler(GdkEvent* event) { break; case GDK_SCROLL: { - GdkEventScroll *scroll_event = (GdkEventScroll*) event; - - if (scroll_event->state & GDK_MOD1_MASK) { // alt modified pressed - if (moved_while_cycling) { - moved_while_cycling = false; - this->sp_select_context_reset_opacities(); - } - is_cycling = true; - - bool shift_pressed = scroll_event->state & GDK_SHIFT_MASK; - - /* Rebuild list of items underneath the mouse pointer */ - Geom::Point p = desktop->d2w(desktop->point()); - SPItem *item = desktop->getItemAtPoint(p, true, NULL); - - // Save pointer to current cycle-item so that we can find it again later, in the freshly built list - SPItem *tmp_cur_item = this->cycling_cur_item!=this->cycling_items.end() ? (*(this->cycling_cur_item)) : NULL; - this->cycling_items.clear(); - this->cycling_cur_item = this->cycling_items.end(); - while(item != NULL) { - this->cycling_items.push_back(item); - item = desktop->getItemAtPoint(p, true, item); - } - - /* Compare current item list with item list during previous scroll ... */ - bool item_lists_differ = this->cycling_items != this->cycling_items_cmp; - - /* If list of items under mouse pointer hasn't changed ... */ - if (!item_lists_differ) { - // ... find current item in the freshly built list and continue cycling ... - // TODO: This wouldn't be necessary if cycling_cur_item pointed to an element of cycling_items_cmp instead - this->cycling_cur_item = std::find(this->cycling_items.begin(), this->cycling_items.end(), tmp_cur_item); - g_assert(this->cycling_cur_item != this->cycling_items.end() || this->cycling_items.empty()); - } else { - // ... otherwise reset opacities for outdated items ... - Inkscape::DrawingItem *arenaitem; - - for (std::vector::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l) { - SPItem *item = *l; - if (item) { - arenaitem = item->get_arenaitem(desktop->dkey); - arenaitem->setOpacity(1.0); - //if (!shift_pressed && !g_list_find(this->cycling_items_selected_before, item) && selection->includes(item)) - if (std::find(this->cycling_items_selected_before.begin(),this->cycling_items_selected_before.end(), item)==this->cycling_items_selected_before.end() && selection->includes(item)) { - selection->remove(item); - } - } - } + GdkEventScroll *scroll_event = (GdkEventScroll*) event; - // ... clear the lists ... + if ( ! (scroll_event->state & GDK_MOD1_MASK)) // do nothing specific if alt was not pressed + break; - this->cycling_items_cmp.clear(); - this->cycling_items_selected_before.clear(); - this->cycling_cur_item = this->cycling_items.end(); + bool shift_pressed = scroll_event->state & GDK_SHIFT_MASK; + is_cycling = true; - // ... and rebuild them with the new items. - this->cycling_items_cmp = (this->cycling_items); + /* Rebuild list of items underneath the mouse pointer */ + Geom::Point p = desktop->d2w(desktop->point()); + SPItem *item = desktop->getItemAtPoint(p, true, NULL); + this->cycling_items.clear(); - for(std::vector::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l) { - SPItem *item =*l; - if (item) { - arenaitem = item->get_arenaitem(desktop->dkey); - arenaitem->setOpacity(0.3); + SPItem *tmp = NULL; + while(item != NULL) { + this->cycling_items.push_back(item); + item = desktop->getItemAtPoint(p, true, item); + if (selection->includes(item)) tmp = item; + } - if (selection->includes(item)) { - // already selected items are stored separately, too - this->cycling_items_selected_before.push_back(item); - } - } else { - g_assert_not_reached(); - } + /* Compare current item list with item list during previous scroll ... */ + bool item_lists_differ = this->cycling_items != this->cycling_items_cmp; + + if(item_lists_differ) { + this->sp_select_context_reset_opacities(); + for (std::vector::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l) + selection->remove(*l); // deselects the previous content of the cycling loop + this->cycling_items_cmp = (this->cycling_items); + + // set opacities in new stack + for(std::vector::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l) { + SPItem *item =*l; + if (item) { + Inkscape::DrawingItem *arenaitem = item->get_arenaitem(desktop->dkey); + arenaitem->setOpacity(0.3); } - - // set the current item to the bottommost one so that the cycling step below re-starts at the top - this->cycling_cur_item = this->cycling_items.end(); - this->cycling_cur_item--; } + } + if(!cycling_cur_item) cycling_cur_item = tmp; - this->cycling_wrap = prefs->getBool("/options/selection/cycleWrap", true); + this->cycling_wrap = prefs->getBool("/options/selection/cycleWrap", true); - // Cycle through the items underneath the mouse pointer, one-by-one - this->sp_select_context_cycle_through_items(selection, scroll_event, shift_pressed); + // Cycle through the items underneath the mouse pointer, one-by-one + this->sp_select_context_cycle_through_items(selection, scroll_event, shift_pressed); - ret = TRUE; + ret = TRUE; - GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel( GTK_WIDGET(desktop->canvas) )); - if (w) - { - gtk_window_present(w); - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); - } + GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel( GTK_WIDGET(desktop->canvas) )); + if (w) { + gtk_window_present(w); + gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); } break; } diff --git a/src/ui/tools/select-tool.h b/src/ui/tools/select-tool.h index af183b1ca..420374661 100644 --- a/src/ui/tools/select-tool.h +++ b/src/ui/tools/select-tool.h @@ -42,8 +42,7 @@ public: std::vector cycling_items; std::vector cycling_items_cmp; - std::vector cycling_items_selected_before; - std::vector::iterator cycling_cur_item; + SPItem *cycling_cur_item; bool cycling_wrap; SPItem *item; -- cgit v1.2.3 From f5eb74652e628b4424647e798da1d0c05d6f4b2f Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Thu, 16 Jun 2016 14:07:58 +0200 Subject: remove tabs (bzr r14989) --- src/ui/tools/select-tool.cpp | 58 ++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index 5b48d65be..b5ec3d88e 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -65,7 +65,7 @@ static gint rb_escaped = 0; // if non-zero, rubberband was canceled by esc, so t static gint drag_escaped = 0; // if non-zero, drag was canceled by esc const std::string& SelectTool::getPrefsPath() { - return SelectTool::prefsPath; + return SelectTool::prefsPath; } const std::string SelectTool::prefsPath = "/tools/select"; @@ -296,7 +296,7 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) { } else { GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); - this->dragging = TRUE; + this->dragging = TRUE; this->moved = FALSE; gdk_window_set_cursor(window, CursorSelectDragging); @@ -346,11 +346,11 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) { break; } case GDK_LEAVE_NOTIFY: - if (!desktop->isWaitingCursor() && !this->dragging) { + if (!desktop->isWaitingCursor() && !this->dragging) { GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); gdk_window_set_cursor(window, this->cursor); - } + } break; case GDK_KEY_PRESS: @@ -378,7 +378,7 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) { } if (!ret) { - ret = ToolBase::item_handler(item, event); + ret = ToolBase::item_handler(item, event); } return ret; @@ -710,7 +710,7 @@ bool SelectTool::root_handler(GdkEvent* event) { if (r->is_started() && !within_tolerance) { // this was a rubberband drag - std::vector items; + std::vector items; if (r->getMode() == RUBBERBAND_MODE_RECT) { Geom::OptRect const b = r->getRectangle(); @@ -860,10 +860,10 @@ bool SelectTool::root_handler(GdkEvent* event) { } case GDK_KEY_PRESS: // keybindings for select context - { - { - guint keyval = get_group0_keyval(&event->key); - + { + { + guint keyval = get_group0_keyval(&event->key); + bool alt = ( MOD__ALT(event) || (keyval == GDK_KEY_Alt_L) || (keyval == GDK_KEY_Alt_R) @@ -891,7 +891,7 @@ bool SelectTool::root_handler(GdkEvent* event) { // if Alt and nonempty selection, show moving cursor ("move selected"): if (alt && !selection->isEmpty() && !desktop->isWaitingCursor()) { - GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); + GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas())); gdk_window_set_cursor(window, CursorSelectDragging); } @@ -912,15 +912,15 @@ bool SelectTool::root_handler(GdkEvent* event) { if (MOD__ALT(event)) { // alt if (MOD__SHIFT(event)) { - sp_selection_move_screen(desktop->getSelection(), mul*-10, 0); // shift + sp_selection_move_screen(desktop->getSelection(), mul*-10, 0); // shift } else { - sp_selection_move_screen(desktop->getSelection(), mul*-1, 0); // no shift + sp_selection_move_screen(desktop->getSelection(), mul*-1, 0); // no shift } } else { // no alt if (MOD__SHIFT(event)) { - sp_selection_move(desktop->getSelection(), mul*-10*nudge, 0); // shift + sp_selection_move(desktop->getSelection(), mul*-10*nudge, 0); // shift } else { - sp_selection_move(desktop->getSelection(), mul*-nudge, 0); // no shift + sp_selection_move(desktop->getSelection(), mul*-nudge, 0); // no shift } } @@ -935,15 +935,15 @@ bool SelectTool::root_handler(GdkEvent* event) { if (MOD__ALT(event)) { // alt if (MOD__SHIFT(event)) { - sp_selection_move_screen(desktop->getSelection(), 0, mul*10); // shift + sp_selection_move_screen(desktop->getSelection(), 0, mul*10); // shift } else { - sp_selection_move_screen(desktop->getSelection(), 0, mul*1); // no shift + sp_selection_move_screen(desktop->getSelection(), 0, mul*1); // no shift } } else { // no alt if (MOD__SHIFT(event)) { - sp_selection_move(desktop->getSelection(), 0, mul*10*nudge); // shift + sp_selection_move(desktop->getSelection(), 0, mul*10*nudge); // shift } else { - sp_selection_move(desktop->getSelection(), 0, mul*nudge); // no shift + sp_selection_move(desktop->getSelection(), 0, mul*nudge); // no shift } } @@ -958,15 +958,15 @@ bool SelectTool::root_handler(GdkEvent* event) { if (MOD__ALT(event)) { // alt if (MOD__SHIFT(event)) { - sp_selection_move_screen(desktop->getSelection(), mul*10, 0); // shift + sp_selection_move_screen(desktop->getSelection(), mul*10, 0); // shift } else { - sp_selection_move_screen(desktop->getSelection(), mul*1, 0); // no shift + sp_selection_move_screen(desktop->getSelection(), mul*1, 0); // no shift } } else { // no alt if (MOD__SHIFT(event)) { - sp_selection_move(desktop->getSelection(), mul*10*nudge, 0); // shift + sp_selection_move(desktop->getSelection(), mul*10*nudge, 0); // shift } else { - sp_selection_move(desktop->getSelection(), mul*nudge, 0); // no shift + sp_selection_move(desktop->getSelection(), mul*nudge, 0); // no shift } } @@ -981,15 +981,15 @@ bool SelectTool::root_handler(GdkEvent* event) { if (MOD__ALT(event)) { // alt if (MOD__SHIFT(event)) { - sp_selection_move_screen(desktop->getSelection(), 0, mul*-10); // shift + sp_selection_move_screen(desktop->getSelection(), 0, mul*-10); // shift } else { - sp_selection_move_screen(desktop->getSelection(), 0, mul*-1); // no shift + sp_selection_move_screen(desktop->getSelection(), 0, mul*-1); // no shift } } else { // no alt if (MOD__SHIFT(event)) { - sp_selection_move(desktop->getSelection(), 0, mul*-10*nudge); // shift + sp_selection_move(desktop->getSelection(), 0, mul*-10*nudge); // shift } else { - sp_selection_move(desktop->getSelection(), 0, mul*-nudge); // no shift + sp_selection_move(desktop->getSelection(), 0, mul*-nudge); // no shift } } @@ -1133,7 +1133,7 @@ bool SelectTool::root_handler(GdkEvent* event) { break; } break; - } + } case GDK_KEY_RELEASE: { guint keyval = get_group0_keyval(&event->key); if (key_is_a_modifier (keyval)) { @@ -1174,7 +1174,7 @@ bool SelectTool::root_handler(GdkEvent* event) { } if (!ret) { - ret = ToolBase::root_handler(event); + ret = ToolBase::root_handler(event); } return ret; -- cgit v1.2.3 From 5d388f13644b59e355e0980c74695247b2191562 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Thu, 16 Jun 2016 22:29:40 +0200 Subject: Fixes some bugs related to powerstroke 'Powerstroke infinite loop' Fixed bugs: - https://launchpad.net/bugs/1535444 - https://launchpad.net/bugs/1236320 - https://launchpad.net/bugs/1586973 (bzr r14991) --- src/2geom/sbasis-geometric.cpp | 9 ++++---- src/live_effects/lpe-powerstroke.cpp | 25 ++++++++-------------- src/ui/tools/freehand-base.cpp | 40 +++++++++--------------------------- 3 files changed, 23 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/2geom/sbasis-geometric.cpp b/src/2geom/sbasis-geometric.cpp index 8aaa15144..19eccc451 100644 --- a/src/2geom/sbasis-geometric.cpp +++ b/src/2geom/sbasis-geometric.cpp @@ -101,7 +101,7 @@ static SBasis divide_by_t1k(SBasis const &a, int k) { static D2 RescaleForNonVanishingEnds(D2 const &MM, double ZERO=1.e-4){ D2 M = MM; //TODO: divide by all the s at once!!! - while ((M[0].size()>0||M[1].size()>0) && + while ((M[0].size()>1||M[1].size()>1) && fabs(M[0].at0()) RescaleForNonVanishingEnds(D2 const &MM, double ZERO=1 M[0] = divide_by_sk(M[0],1); M[1] = divide_by_sk(M[1],1); } - while ((M[0].size()>0||M[1].size()>0) && + while ((M[0].size()>1||M[1].size()>1) && fabs(M[0].at0())0||M[1].size()>0) && + while ((M[0].size()>1||M[1].size()>1) && fabs(M[0].at1()) const &V_in, double tol, unsigned order){ // -This approach is numerically bad. Find a stable way to rescale V_in to have non vanishing ends. // -This done, unitVector will have jumps at zeros: fill the gaps with arcs of circles. D2 V = RescaleForNonVanishingEnds(V_in); - if (V[0].isZero(0) && V[1].isZero(0)) return Piecewise >(D2(Linear(1),SBasis())); + SBasis x = V[0], y = V[1]; SBasis r_eqn1, r_eqn2; @@ -242,7 +242,6 @@ Geom::unitVector(D2 const &V_in, double tol, unsigned order){ r_eqn1 = -(a*x+b*y); r_eqn2 = Linear(1.)-(a*a+b*b); - for (unsigned k=1; k<=order; k++){ double r0 = (k #include <2geom/circle.h> #include <2geom/math-utils.h> +#include "helper/geom.h" #include #include "spiro.h" @@ -205,14 +206,13 @@ LPEPowerStroke::~LPEPowerStroke() } - void LPEPowerStroke::doOnApply(SPLPEItem const* lpeitem) { - if (SP_IS_SHAPE(lpeitem)) { + if (SP_IS_SHAPE(lpeitem) && offset_points.data().empty()) { SPLPEItem* item = const_cast(lpeitem); std::vector points; - Geom::PathVector const &pathv = SP_SHAPE(lpeitem)->_curve->get_pathvector(); + Geom::PathVector const &pathv = pathv_to_linear_and_cubic_beziers(SP_SHAPE(lpeitem)->_curve->get_pathvector()); double width = (lpeitem && lpeitem->style) ? lpeitem->style->stroke_width.computed / 2 : 1.; SPCSSAttr *css = sp_repr_css_attr_new (); @@ -565,12 +565,11 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) if (path_in.empty()) { return path_out; } - - // for now, only regard first subpath and ignore the rest - Geom::Piecewise > pwd2_in = path_in[0].toPwSb(); - + Geom::PathVector pathv = pathv_to_linear_and_cubic_beziers(path_in); + Geom::Piecewise > pwd2_in = pathv[0].toPwSb(); Piecewise > der = derivative(pwd2_in); - Piecewise > n = rot90(unitVector(der)); + Piecewise > n = unitVector(der,0.0001); + n = rot90(n); offset_points.set_pwd2(pwd2_in, n); LineCapType end_linecap = static_cast(end_linecap_type.get_value()); @@ -583,7 +582,7 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) if (sort_points) { sort(ts.begin(), ts.end(), compare_offsets); } - if (path_in[0].closed()) { + if (pathv[0].closed()) { // add extra points for interpolation between first and last point Point first_point = ts.front(); Point last_point = ts.back(); @@ -605,7 +604,6 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) for (std::size_t i = 0, e = ts.size(); i < e; ++i) { ts[i][Geom::X] *= xcoord_scaling; } - // create stroke path where points (x,y) := (t, offset) Geom::Interpolate::Interpolator *interpolator = Geom::Interpolate::Interpolator::create(static_cast(interpolator_type.get_value())); if (Geom::Interpolate::CubicBezierJohan *johan = dynamic_cast(interpolator)) { @@ -631,7 +629,6 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) x = portion(x, rtsmin.at(0), rtsmax.at(0)); y = portion(y, rtsmin.at(0), rtsmax.at(0)); } - LineJoinType jointype = static_cast(linejoin_type.get_value()); Piecewise > pwd2_out = compose(pwd2_in,x) + y*compose(n,x); @@ -639,8 +636,7 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) Geom::Path fixed_path = path_from_piecewise_fix_cusps( pwd2_out, y, jointype, miter_limit, LPE_CONVERSION_TOLERANCE); Geom::Path fixed_mirrorpath = path_from_piecewise_fix_cusps( mirrorpath, reverse(y), jointype, miter_limit, LPE_CONVERSION_TOLERANCE); - - if (path_in[0].closed()) { + if (pathv[0].closed()) { fixed_path.close(true); path_out.push_back(fixed_path); fixed_mirrorpath.close(true); @@ -684,7 +680,6 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) } fixed_path.append(fixed_mirrorpath); - switch (start_linecap) { case LINECAP_ZERO_WIDTH: // do nothing @@ -720,11 +715,9 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) break; } } - fixed_path.close(true); path_out.push_back(fixed_path); } - return path_out; } diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index c98ecb686..7697cd59c 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -236,38 +236,14 @@ static void spdc_apply_powerstroke_shape(const std::vector & points Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE(); static_cast(lpe)->offset_points.param_set_and_write_new_value(points); - // find out stroke width (TODO: is there an easier way??) - SPDesktop *desktop = dc->desktop; - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); - Inkscape::GC::release(repr); - - char const* tool = SP_IS_PEN_CONTEXT(dc) ? "/tools/freehand/pen" : "/tools/freehand/pencil"; - - // apply the tool's current style - sp_desktop_apply_style_tool(desktop, repr, tool, false); - - double stroke_width = 1.0; - char const *style_str = NULL; - style_str = repr->attribute("style"); - if (style_str) { - SPStyle style(SP_ACTIVE_DOCUMENT); - style.mergeString(style_str); - stroke_width = style.stroke_width.computed; - } - - std::ostringstream s; - s.imbue(std::locale::classic()); - s << points[0][Geom::X] << "," << stroke_width / 2.; - // write powerstroke parameters: lpe->getRepr()->setAttribute("start_linecap_type", "zerowidth"); lpe->getRepr()->setAttribute("end_linecap_type", "zerowidth"); - lpe->getRepr()->setAttribute("cusp_linecap_type", "round"); lpe->getRepr()->setAttribute("sort_points", "true"); lpe->getRepr()->setAttribute("interpolator_type", "CubicBezierJohan"); lpe->getRepr()->setAttribute("interpolator_beta", "0.2"); - lpe->getRepr()->setAttribute("offset_points", s.str().c_str()); + lpe->getRepr()->setAttribute("miter_limit", "4"); + lpe->getRepr()->setAttribute("linejoin_type", "extrp_arc"); } static void spdc_apply_bend_shape(gchar const *svgd, FreehandBase *dc, SPItem *item) @@ -341,12 +317,14 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, bool shape_applied = false; SPCSSAttr *css_item = sp_css_attr_from_object(item, SP_STYLE_FLAG_ALWAYS); const char *cstroke = sp_repr_css_property(css_item, "stroke", "none"); + const char *stroke_width = sp_repr_css_property(css_item, "stroke-width", "0"); + double swidth; + sp_svg_number_read_d(stroke_width, &swidth); static SPItem *bend_item; #define SHAPE_LENGTH 10 #define SHAPE_HEIGHT 10 - if(shape == LAST_APPLIED){ shape = previous_shape_type; @@ -363,7 +341,8 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, { // "triangle in" std::vector points(1); - points[0] = Geom::Point(0., SHAPE_HEIGHT/2); + points[0] = Geom::Point(0., swidth/2); + points[0] *= i2anc_affine(static_cast(item->parent), NULL).inverse(); spdc_apply_powerstroke_shape(points, dc, item); shape_applied = true; @@ -374,7 +353,9 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, // "triangle out" guint curve_length = curve->get_segment_count(); std::vector points(1); - points[0] = Geom::Point((double)curve_length, SHAPE_HEIGHT/2); + points[0] = Geom::Point(0, swidth/2); + points[0] *= i2anc_affine(static_cast(item->parent), NULL).inverse(); + points[0][Geom::X] = (double)curve_length; spdc_apply_powerstroke_shape(points, dc, item); shape_applied = true; @@ -455,7 +436,6 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, if(previous_shape_type == CLIPBOARD){ if(previous_shape_pathv.size() != 0){ spdc_paste_curve_as_freehand_shape(previous_shape_pathv, dc, item); - shape_applied = true; shape = CLIPBOARD; } else{ -- cgit v1.2.3 From 736149f0b6b617c2cf6f6bef55b4606cd70e416b Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 17 Jun 2016 11:22:07 +0530 Subject: Remove unwanted empty space at top in style dialog (bzr r14949.1.21) --- src/ui/dialog/styledialog.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index a56277054..622bbcdb9 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -53,7 +53,6 @@ StyleDialog::StyleDialog() : _desktop(0) { set_size_request(200, 200); - add(_mainBox); _mainBox.pack_start(_scrolledWindow, Gtk::PACK_EXPAND_WIDGET); _treeView.set_headers_visible(false); @@ -80,10 +79,13 @@ StyleDialog::StyleDialog() : &StyleDialog::_delSelector)); del->set_sensitive(false); - _mainBox.pack_start(_buttonBox, Gtk::PACK_SHRINK); + _mainBox.pack_end(_buttonBox, Gtk::PACK_SHRINK); + _buttonBox.pack_start(*create, Gtk::PACK_SHRINK); _buttonBox.pack_start(*del, Gtk::PACK_SHRINK); + _getContents()->pack_start(_mainBox, Gtk::PACK_EXPAND_WIDGET); + _targetDesktop = getDesktop(); setDesktop(_targetDesktop); -- cgit v1.2.3 From 027da41d7212e9ecaf19439f91266d4888ae96e3 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Fri, 17 Jun 2016 08:14:16 +0200 Subject: Fixing wrong gettext keyword preventing translations from being used. (bzr r14992) --- src/ui/tools/measure-tool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 0977729ae..63e2460ec 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -346,13 +346,13 @@ MeasureTool::MeasureTool() end_p = readMeasurePoint(false); dimension_offset = 35; // create the knots - this->knot_start = new SPKnot(desktop, N_("Measure start, Shift+Click for position dialog")); + this->knot_start = new SPKnot(desktop, _("Measure start, Shift+Click for position dialog")); this->knot_start->setMode(SP_KNOT_MODE_XOR); this->knot_start->setFill(MT_KNOT_COLOR_NORMAL, MT_KNOT_COLOR_MOUSEOVER, MT_KNOT_COLOR_MOUSEOVER); this->knot_start->setStroke(0x0000007f, 0x0000007f, 0x0000007f); this->knot_start->setShape(SP_KNOT_SHAPE_CIRCLE); this->knot_start->updateCtrl(); - this->knot_end = new SPKnot(desktop, N_("Measure end, Shift+Click for position dialog")); + this->knot_end = new SPKnot(desktop, _("Measure end, Shift+Click for position dialog")); this->knot_end->setMode(SP_KNOT_MODE_XOR); this->knot_end->setFill(MT_KNOT_COLOR_NORMAL, MT_KNOT_COLOR_MOUSEOVER, MT_KNOT_COLOR_MOUSEOVER); this->knot_end->setStroke(0x0000007f, 0x0000007f, 0x0000007f); -- cgit v1.2.3 From 0ce1eb6fcfa054641be8225cf65ef7d01bf0a813 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 17 Jun 2016 14:49:21 +0530 Subject: Fix a crash while deleting when there was single selector in the style dialog (bzr r14949.1.23) --- src/ui/dialog/styledialog.cpp | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 622bbcdb9..f81faec97 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -283,17 +283,44 @@ void StyleDialog::_delSelector() Gtk::TreeModel::Row row = *iter; path = _treeView.get_model()->get_path(iter); int i = atoi(path.to_string().c_str()); - selVec.erase(selVec.begin()+i); - _sValue.clear(); - for (unsigned i = 0; i < selVec.size(); ++i) + if (selVec.size() != 0) { - std::string selValue = (selVec[i].first + "{" - + selVec[i].second + " }\n"); - _sValue.append(selValue.c_str()); - } + selVec.erase(selVec.begin()+i); + _sValue.clear(); + + if (selVec.size() != 0) + { + for (unsigned i = 0; i < selVec.size(); ++i) + { + std::string selValue = (selVec[i].first + "{" + + selVec[i].second + " }\n"); + _sValue.append(selValue.c_str()); + } - _styleChild->firstChild()->setContent(_sValue.c_str()); + } + + /** + * Only if a value exists in _sValue and there is a _styleChild + * which contains the style element, then the content in style + * element is updated else the _styleChild is set and its content + * is set to an empty string. + */ + if (!_sValue.empty() && _styleChild) + _styleChild->firstChild()->setContent(_sValue.c_str()); + else + { + for ( unsigned i = 0; i < _num; ++i ) + { + if ( std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style" ) + { + _styleChild = _document->getReprRoot()->nthChild(i); + } + } + _styleChild->firstChild()->setContent(""); + } + } _store->erase(row); } } -- 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 71959483ca7952c2b90c9b04651c187b6e17a19b Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sun, 19 Jun 2016 16:29:01 +0530 Subject: Resolve crash when empty string was added via entrybox in style dialog (bzr r14949.1.24) --- src/ui/dialog/styledialog.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index f81faec97..a7a803edd 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -155,11 +155,16 @@ void StyleDialog::_addSelector() * with a dot. */ std::string selectorName = ""; - if ( textEditPtr->get_text().at(0) == '#' || - textEditPtr->get_text().at(0) == '.' ) - selectorName = textEditPtr->get_text(); - else - selectorName = "." + textEditPtr->get_text(); + if ( !textEditPtr->get_text().empty() ) { + if ( textEditPtr->get_text().at(0) == '#' || + textEditPtr->get_text().at(0) == '.' ) + selectorName = textEditPtr->get_text(); + else + selectorName = "." + textEditPtr->get_text(); + } + else { + selectorName = ".Class1"; + } switch (result) { case Gtk::RESPONSE_OK: -- cgit v1.2.3 From b65581bd7a768c78115a8a0a807e79a2ee91e80e Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Mon, 20 Jun 2016 18:57:07 +0200 Subject: Fixing missing gettext keyword (regression introduced rev. 14057). (bzr r14997) --- src/widgets/paintbucket-toolbar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/widgets/paintbucket-toolbar.cpp b/src/widgets/paintbucket-toolbar.cpp index eb55287c4..5cb2dd58b 100644 --- a/src/widgets/paintbucket-toolbar.cpp +++ b/src/widgets/paintbucket-toolbar.cpp @@ -127,7 +127,7 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions iterator != channel_list.end(); ++iterator ) { GtkTreeIter iter; gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, (*iterator).c_str(), 1, count, -1 ); + gtk_list_store_set( model, &iter, 0, _((*iterator).c_str()), 1, count, -1 ); count++; } @@ -193,7 +193,7 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions iterator != gap_list.end(); ++iterator ) { GtkTreeIter iter; gtk_list_store_append( model, &iter ); - gtk_list_store_set( model, &iter, 0, (*iterator).c_str(), 1, count, -1 ); + gtk_list_store_set( model, &iter, 0, _((*iterator).c_str()), 1, count, -1 ); count++; } EgeSelectOneAction* act2 = ege_select_one_action_new( "AutoGapAction", _("Close gaps"), (""), NULL, GTK_TREE_MODEL(model) ); -- cgit v1.2.3 From dfbba183bcd15fca6508da6feecde95c0b4f4c20 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 20 Jun 2016 21:54:26 -0500 Subject: Make the relocatable paths relative to the lib install (bzr r14950.1.7) --- src/path-prefix.h | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/path-prefix.h b/src/path-prefix.h index 7f9bcec51..d63fba7fc 100644 --- a/src/path-prefix.h +++ b/src/path-prefix.h @@ -21,28 +21,28 @@ //#endif /* __cplusplus */ #ifdef ENABLE_BINRELOC -# define INKSCAPE_APPICONDIR BR_DATADIR( "/pixmaps" ) -# define INKSCAPE_ATTRRELDIR BR_DATADIR( "/inkscape/attributes" ) -# define INKSCAPE_BINDDIR BR_DATADIR( "/inkscape/bind" ) -# define INKSCAPE_EXAMPLESDIR BR_DATADIR( "/inkscape/examples" ) -# define INKSCAPE_EXTENSIONDIR BR_DATADIR( "/inkscape/extensions" ) -# define INKSCAPE_FILTERDIR BR_DATADIR( "/inkscape/filters" ) -# define INKSCAPE_GRADIENTSDIR BR_DATADIR( "/inkscape/gradients" ) -# define INKSCAPE_KEYSDIR BR_DATADIR( "/inkscape/keys" ) -# define INKSCAPE_PIXMAPDIR BR_DATADIR( "/inkscape/icons" ) -# define INKSCAPE_MARKERSDIR BR_DATADIR( "/inkscape/markers" ) -# define INKSCAPE_PALETTESDIR BR_DATADIR( "/inkscape/palettes" ) -# define INKSCAPE_PATTERNSDIR BR_DATADIR( "/inkscape/patterns" ) -# define INKSCAPE_SCREENSDIR BR_DATADIR( "/inkscape/screens" ) -# define INKSCAPE_SYMBOLSDIR BR_DATADIR( "/inkscape/symbols" ) -# define INKSCAPE_THEMEDIR BR_DATADIR( "/icons" ) -# define INKSCAPE_TUTORIALSDIR BR_DATADIR( "/inkscape/tutorials" ) -# define INKSCAPE_TEMPLATESDIR BR_DATADIR( "/inkscape/templates" ) -# define INKSCAPE_UIDIR BR_DATADIR( "/inkscape/ui" ) +# define INKSCAPE_APPICONDIR BR_DATADIR( "/../share/pixmaps" ) +# define INKSCAPE_ATTRRELDIR BR_DATADIR( "/../share/inkscape/attributes" ) +# define INKSCAPE_BINDDIR BR_DATADIR( "/../share/inkscape/bind" ) +# define INKSCAPE_EXAMPLESDIR BR_DATADIR( "/../share/inkscape/examples" ) +# define INKSCAPE_EXTENSIONDIR BR_DATADIR( "/../share/inkscape/extensions" ) +# define INKSCAPE_FILTERDIR BR_DATADIR( "/../share/inkscape/filters" ) +# define INKSCAPE_GRADIENTSDIR BR_DATADIR( "/../share/inkscape/gradients" ) +# define INKSCAPE_KEYSDIR BR_DATADIR( "/../share/inkscape/keys" ) +# define INKSCAPE_PIXMAPDIR BR_DATADIR( "/../share/inkscape/icons" ) +# define INKSCAPE_MARKERSDIR BR_DATADIR( "/../share/inkscape/markers" ) +# define INKSCAPE_PALETTESDIR BR_DATADIR( "/../share/inkscape/palettes" ) +# define INKSCAPE_PATTERNSDIR BR_DATADIR( "/../share/inkscape/patterns" ) +# define INKSCAPE_SCREENSDIR BR_DATADIR( "/../share/inkscape/screens" ) +# define INKSCAPE_SYMBOLSDIR BR_DATADIR( "/../share/inkscape/symbols" ) +# define INKSCAPE_THEMEDIR BR_DATADIR( "/../share/icons" ) +# define INKSCAPE_TUTORIALSDIR BR_DATADIR( "/../share/inkscape/tutorials" ) +# define INKSCAPE_TEMPLATESDIR BR_DATADIR( "/../share/inkscape/templates" ) +# define INKSCAPE_UIDIR BR_DATADIR( "/../share/inkscape/ui" ) //CREATE V0.1 support -# define CREATE_GRADIENTSDIR BR_DATADIR( "/create/gradients/gimp" ) -# define CREATE_PALETTESDIR BR_DATADIR( "/create/swatches" ) -# define CREATE_PATTERNSDIR BR_DATADIR( "/create/patterns/vector" ) +# define CREATE_GRADIENTSDIR BR_DATADIR( "/../share/create/gradients/gimp" ) +# define CREATE_PALETTESDIR BR_DATADIR( "/../share/create/swatches" ) +# define CREATE_PATTERNSDIR BR_DATADIR( "/../share/create/patterns/vector" ) #else # ifdef WIN32 # define INKSCAPE_APPICONDIR WIN32_DATADIR("pixmaps") -- cgit v1.2.3 From 61343ac879caaf278c1b5e83c5f05d5798affae6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 20 Jun 2016 22:37:49 -0500 Subject: Adjust directories to be lib based (bzr r14950.1.8) --- src/path-prefix.h | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/path-prefix.h b/src/path-prefix.h index d63fba7fc..3e226dd97 100644 --- a/src/path-prefix.h +++ b/src/path-prefix.h @@ -21,28 +21,29 @@ //#endif /* __cplusplus */ #ifdef ENABLE_BINRELOC -# define INKSCAPE_APPICONDIR BR_DATADIR( "/../share/pixmaps" ) -# define INKSCAPE_ATTRRELDIR BR_DATADIR( "/../share/inkscape/attributes" ) -# define INKSCAPE_BINDDIR BR_DATADIR( "/../share/inkscape/bind" ) -# define INKSCAPE_EXAMPLESDIR BR_DATADIR( "/../share/inkscape/examples" ) -# define INKSCAPE_EXTENSIONDIR BR_DATADIR( "/../share/inkscape/extensions" ) -# define INKSCAPE_FILTERDIR BR_DATADIR( "/../share/inkscape/filters" ) -# define INKSCAPE_GRADIENTSDIR BR_DATADIR( "/../share/inkscape/gradients" ) -# define INKSCAPE_KEYSDIR BR_DATADIR( "/../share/inkscape/keys" ) -# define INKSCAPE_PIXMAPDIR BR_DATADIR( "/../share/inkscape/icons" ) -# define INKSCAPE_MARKERSDIR BR_DATADIR( "/../share/inkscape/markers" ) -# define INKSCAPE_PALETTESDIR BR_DATADIR( "/../share/inkscape/palettes" ) -# define INKSCAPE_PATTERNSDIR BR_DATADIR( "/../share/inkscape/patterns" ) -# define INKSCAPE_SCREENSDIR BR_DATADIR( "/../share/inkscape/screens" ) -# define INKSCAPE_SYMBOLSDIR BR_DATADIR( "/../share/inkscape/symbols" ) -# define INKSCAPE_THEMEDIR BR_DATADIR( "/../share/icons" ) -# define INKSCAPE_TUTORIALSDIR BR_DATADIR( "/../share/inkscape/tutorials" ) -# define INKSCAPE_TEMPLATESDIR BR_DATADIR( "/../share/inkscape/templates" ) -# define INKSCAPE_UIDIR BR_DATADIR( "/../share/inkscape/ui" ) +# define INKSCAPE_LIBPREFIX "/../.." +# define INKSCAPE_APPICONDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/pixmaps" ) +# define INKSCAPE_ATTRRELDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/attributes" ) +# define INKSCAPE_BINDDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/bind" ) +# define INKSCAPE_EXAMPLESDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/examples" ) +# define INKSCAPE_EXTENSIONDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/extensions" ) +# define INKSCAPE_FILTERDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/filters" ) +# define INKSCAPE_GRADIENTSDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/gradients" ) +# define INKSCAPE_KEYSDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/keys" ) +# define INKSCAPE_PIXMAPDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/icons" ) +# define INKSCAPE_MARKERSDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/markers" ) +# define INKSCAPE_PALETTESDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/palettes" ) +# define INKSCAPE_PATTERNSDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/patterns" ) +# define INKSCAPE_SCREENSDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/screens" ) +# define INKSCAPE_SYMBOLSDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/symbols" ) +# define INKSCAPE_THEMEDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/icons" ) +# define INKSCAPE_TUTORIALSDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/tutorials" ) +# define INKSCAPE_TEMPLATESDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/templates" ) +# define INKSCAPE_UIDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/ui" ) //CREATE V0.1 support -# define CREATE_GRADIENTSDIR BR_DATADIR( "/../share/create/gradients/gimp" ) -# define CREATE_PALETTESDIR BR_DATADIR( "/../share/create/swatches" ) -# define CREATE_PATTERNSDIR BR_DATADIR( "/../share/create/patterns/vector" ) +# define CREATE_GRADIENTSDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/create/gradients/gimp" ) +# define CREATE_PALETTESDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/create/swatches" ) +# define CREATE_PATTERNSDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/create/patterns/vector" ) #else # ifdef WIN32 # define INKSCAPE_APPICONDIR WIN32_DATADIR("pixmaps") -- cgit v1.2.3 From 1a20f71053ab79c1f130ce592a2557a79d03b195 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 21 Jun 2016 08:08:22 -0500 Subject: Adding a comment to explain what we're doing (bzr r14950.1.10) --- src/path-prefix.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/path-prefix.h b/src/path-prefix.h index 3e226dd97..8a39ede84 100644 --- a/src/path-prefix.h +++ b/src/path-prefix.h @@ -21,6 +21,10 @@ //#endif /* __cplusplus */ #ifdef ENABLE_BINRELOC +/* The way that we're building now is with a shared library between Inkscape + and Inkview, and the code will find the path to the library then. But we + don't really want that. This prefix then pulls things out of the lib directory + and back into the root install dir. */ # define INKSCAPE_LIBPREFIX "/../.." # define INKSCAPE_APPICONDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/pixmaps" ) # define INKSCAPE_ATTRRELDIR BR_DATADIR( INKSCAPE_LIBPREFIX "/share/inkscape/attributes" ) -- cgit v1.2.3 From a2abc287716054efec7514b36e4ec6beb69400bc Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Thu, 23 Jun 2016 07:48:07 +0200 Subject: [Bug #1594542] Reset paint buckets parameters icon is not visible in Tool Controls Bar. Fixed bugs: - https://launchpad.net/bugs/1594542 (bzr r15001) --- src/widgets/paintbucket-toolbar.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/widgets/paintbucket-toolbar.cpp b/src/widgets/paintbucket-toolbar.cpp index 5cb2dd58b..b717d74fa 100644 --- a/src/widgets/paintbucket-toolbar.cpp +++ b/src/widgets/paintbucket-toolbar.cpp @@ -42,6 +42,7 @@ #include "ui/uxmanager.h" #include "ui/widget/unit-tracker.h" #include "util/units.h" +#include "widgets/ink-action.h" using Inkscape::UI::Widget::UnitTracker; using Inkscape::UI::UXManager; @@ -207,13 +208,14 @@ void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions /* Reset */ { - GtkAction* act = gtk_action_new( "PaintbucketResetAction", + InkAction* inky = ink_action_new( "PaintbucketResetAction", _("Defaults"), _("Reset paint bucket parameters to defaults (use Inkscape Preferences > Tools to change defaults)"), - INKSCAPE_ICON("edit-clear")); - g_signal_connect_after( G_OBJECT(act), "activate", G_CALLBACK(paintbucket_defaults), holder ); - gtk_action_group_add_action( mainActions, act ); - gtk_action_set_sensitive( act, TRUE ); + INKSCAPE_ICON("edit-clear"), + Inkscape::ICON_SIZE_SMALL_TOOLBAR); + g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(paintbucket_defaults), holder ); + gtk_action_group_add_action( mainActions, GTK_ACTION(inky) ); + gtk_action_set_sensitive( GTK_ACTION(inky), TRUE ); } } -- cgit v1.2.3 From a4ba7249e4e4510665860eebb43262b0ec7612b0 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 25 Jun 2016 20:55:14 +0200 Subject: Fix bug#168286 also opem regression on bug#1594565 Fixed bugs: - https://launchpad.net/bugs/168286 (bzr r15002) --- src/sp-item-group.cpp | 104 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 83d67cf5a..70d2bc732 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -53,6 +53,10 @@ #include "layer-model.h" #include "sp-textpath.h" #include "sp-flowtext.h" +#include "sp-tspan.h" +#include "selection-chemistry.h" +#include "xml/sp-css-attr.h" +#include "svg/css-ostringstream.h" using Inkscape::DocumentUndo; @@ -388,6 +392,89 @@ void sp_item_group_ungroup_handle_clones(SPItem *parent, Geom::Affine const g) } } +void +sp_recursive_scale_text_size(Inkscape::XML::Node *repr, double scale){ + for (Inkscape::XML::Node *child = repr->firstChild() ; child; child = child->next() ){ + if ( child) { + sp_recursive_scale_text_size(child, scale); + } + } + SPCSSAttr * css = sp_repr_css_attr(repr,"style"); + Glib::ustring element = g_quark_to_string(repr->code()); + if (css && element == "svg:text" || element == "svg:tspan") { + gchar const *w = sp_repr_css_property(css, "font-size", NULL); + if (w) { + gchar *units = NULL; + double wd = g_ascii_strtod(w, &units); + wd *= scale; + if (w != units) { + Inkscape::CSSOStringStream os; + os << wd << units; // reattach units + sp_repr_css_set_property(css, "font-size", os.str().c_str()); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + repr->setAttribute("style", css_str.c_str()); + } + } + w = NULL; + w = sp_repr_css_property(css, "letter-spacing", NULL); + if (w) { + gchar *units = NULL; + double wd = g_ascii_strtod(w, &units); + wd *= scale; + if (w != units) { + Inkscape::CSSOStringStream os; + os << wd << units; // reattach units + sp_repr_css_set_property(css, "letter-spacing", os.str().c_str()); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + repr->setAttribute("style", css_str.c_str()); + } + } + w = NULL; + w = sp_repr_css_property(css, "word-spacing", NULL); + if (w) { + gchar *units = NULL; + double wd = g_ascii_strtod(w, &units); + wd *= scale; + if (w != units) { + Inkscape::CSSOStringStream os; + os << wd << units; // reattach units + sp_repr_css_set_property(css, "word-spacing", os.str().c_str()); + Glib::ustring css_str; + sp_repr_css_write_string(css,css_str); + repr->setAttribute("style", css_str.c_str()); + } + } + gchar const *dx = repr->attribute("dx"); + if (dx) { + gchar ** dxarray = g_strsplit(dx, " ", 0); + Inkscape::SVGOStringStream dx_data; + while (*dxarray != NULL) { + double pos; + sp_svg_number_read_d(*dxarray, &pos); + pos *= scale; + dx_data << pos << " "; + dxarray++; + } + repr->setAttribute("dx", dx_data.str().c_str()); + } + gchar const *dy = repr->attribute("dy"); + if (dy) { + gchar ** dyarray = g_strsplit(dy, " ", 0); + Inkscape::SVGOStringStream dy_data; + while (*dyarray != NULL) { + double pos; + sp_svg_number_read_d(*dyarray, &pos); + pos *= scale; + dy_data << pos << " "; + dyarray++; + } + repr->setAttribute("dy", dy_data.str().c_str()); + } + } +} + void sp_item_group_ungroup (SPGroup *group, std::vector &children, bool do_done) { @@ -492,7 +579,22 @@ sp_item_group_ungroup (SPGroup *group, std::vector &children, bool do_d // reattached outside of the group, the transform will be written more properly // (i.e. optimized into the object if the corresponding preference is set) gchar *affinestr=sp_svg_transform_write(ctrans); - nrepr->setAttribute("transform", affinestr); + SPText * text = dynamic_cast(citem); + if (text) { + //this causes a change in text-on-path appearance when there is a non-conformal transform, see bug #1594565 + double scale = (ctrans.expansionX() + ctrans.expansionY()) / 2.0; + SPTextPath * text_path = dynamic_cast(text->children); + if (!text_path) { + nrepr->setAttribute("transform", affinestr); + } else { + sp_recursive_scale_text_size(nrepr, scale); + Geom::Affine ttrans = ctrans.inverse() * SP_ITEM(text)->transform * ctrans; + gchar *affinestr = sp_svg_transform_write(ttrans); + nrepr->setAttribute("transform", affinestr); + } + } else { + nrepr->setAttribute("transform", affinestr); + } g_free(affinestr); items = g_slist_prepend (items, nrepr); -- cgit v1.2.3 From 1636c1dd1651780d01759676b194312529f211f7 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Sat, 25 Jun 2016 22:24:26 +0200 Subject: Moved next functions, added namespace, renamed range functions (bzr r14954.1.10) --- src/desktop-style.cpp | 6 +- src/extension/execution-env.cpp | 2 +- src/extension/implementation/implementation.cpp | 2 +- src/extension/implementation/script.cpp | 2 +- src/extension/internal/bitmap/imagemagick.cpp | 4 +- src/extension/internal/bluredge.cpp | 2 +- src/extension/internal/filter/filter.cpp | 2 +- src/extension/internal/grid.cpp | 2 +- src/extension/plugins/grid2/grid.cpp | 2 +- src/gradient-chemistry.cpp | 4 +- src/gradient-drag.cpp | 6 +- src/object-set.cpp | 31 +++++++--- src/object-set.h | 27 +++++++- src/path-chemistry.cpp | 10 +-- src/selcue.cpp | 8 +-- src/selection-chemistry.cpp | 82 ++++++++++++------------- src/selection-describer.cpp | 2 +- src/selection.cpp | 18 +----- src/selection.h | 16 ----- src/seltrans.cpp | 14 ++--- src/snap.cpp | 2 +- src/splivarot.cpp | 10 +-- src/text-chemistry.cpp | 24 ++++---- src/trace/trace.cpp | 2 +- src/ui/clipboard.cpp | 6 +- src/ui/dialog/align-and-distribute.cpp | 16 ++--- src/ui/dialog/clonetiler.cpp | 8 +-- src/ui/dialog/export.cpp | 14 ++--- src/ui/dialog/filter-effects-dialog.cpp | 6 +- src/ui/dialog/find.cpp | 2 +- src/ui/dialog/glyphs.cpp | 4 +- src/ui/dialog/grid-arrange-tab.cpp | 12 ++-- src/ui/dialog/icon-preview.cpp | 2 +- src/ui/dialog/objects.cpp | 2 +- src/ui/dialog/pixelartdialog.cpp | 2 +- src/ui/dialog/polar-arrange-tab.cpp | 2 +- src/ui/dialog/svg-fonts-dialog.cpp | 4 +- src/ui/dialog/swatches.cpp | 2 +- src/ui/dialog/tags.cpp | 4 +- src/ui/dialog/text-edit.cpp | 6 +- src/ui/dialog/transformation.cpp | 14 ++--- src/ui/interface.cpp | 2 +- src/ui/tools/connector-tool.cpp | 2 +- src/ui/tools/eraser-tool.cpp | 4 +- src/ui/tools/gradient-tool.cpp | 14 ++--- src/ui/tools/lpe-tool.cpp | 2 +- src/ui/tools/mesh-tool.cpp | 12 ++-- src/ui/tools/node-tool.cpp | 4 +- src/ui/tools/select-tool.cpp | 2 +- src/ui/tools/spray-tool.cpp | 10 +-- src/ui/tools/tool-base.cpp | 2 +- src/ui/tools/tweak-tool.cpp | 6 +- src/ui/widget/style-subject.cpp | 2 +- src/vanishing-point.cpp | 10 +-- src/widgets/arc-toolbar.cpp | 8 +-- src/widgets/connector-toolbar.cpp | 6 +- src/widgets/fill-style.cpp | 2 +- src/widgets/gradient-toolbar.cpp | 6 +- src/widgets/mesh-toolbar.cpp | 4 +- src/widgets/pencil-toolbar.cpp | 4 +- src/widgets/rect-toolbar.cpp | 4 +- src/widgets/spiral-toolbar.cpp | 4 +- src/widgets/star-toolbar.cpp | 12 ++-- src/widgets/stroke-style.cpp | 6 +- src/widgets/text-toolbar.cpp | 8 +-- 65 files changed, 266 insertions(+), 256 deletions(-) (limited to 'src') diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 7f9b46c7d..6fab01f16 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -194,7 +194,7 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write sp_repr_css_merge(css_write, css); sp_css_attr_unset_uris(css_write); prefs->mergeStyle("/desktop/style", css_write); - std::vector const itemlist = desktop->selection->itemList(); + std::vector const itemlist = desktop->selection->items(); for (std::vector::const_iterator i = itemlist.begin(); i!= itemlist.end(); ++i) { /* last used styles for 3D box faces are stored separately */ SPObject *obj = *i; @@ -234,7 +234,7 @@ sp_desktop_set_style(SPDesktop *desktop, SPCSSAttr *css, bool change, bool write sp_repr_css_merge(css_no_text, css); css_no_text = sp_css_attr_unset_text(css_no_text); - std::vector const itemlist = desktop->selection->itemList(); + std::vector const itemlist = desktop->selection->items(); for (std::vector::const_iterator i = itemlist.begin(); i!= itemlist.end(); ++i) { SPItem *item = *i; @@ -1917,7 +1917,7 @@ sp_desktop_query_style(SPDesktop *desktop, SPStyle *style, int property) // otherwise, do querying and averaging over selection if (desktop->selection != NULL) { - return sp_desktop_query_style_from_list (desktop->selection->itemList(), style, property); + return sp_desktop_query_style_from_list (desktop->selection->items(), style, property); } return QUERY_STYLE_NOTHING; diff --git a/src/extension/execution-env.cpp b/src/extension/execution-env.cpp index d5c80f26e..2b0183d4b 100644 --- a/src/extension/execution-env.cpp +++ b/src/extension/execution-env.cpp @@ -58,7 +58,7 @@ ExecutionEnv::ExecutionEnv (Effect * effect, Inkscape::UI::View::View * doc, Imp sp_namedview_document_from_window(desktop); if (desktop != NULL) { - std::vector selected = desktop->getSelection()->itemList(); + std::vector selected = desktop->getSelection()->items(); for(std::vector::const_iterator x = selected.begin(); x != selected.end(); ++x){ Glib::ustring selected_id; selected_id = (*x)->getId(); diff --git a/src/extension/implementation/implementation.cpp b/src/extension/implementation/implementation.cpp index 92a8a2833..eb1213a84 100644 --- a/src/extension/implementation/implementation.cpp +++ b/src/extension/implementation/implementation.cpp @@ -46,7 +46,7 @@ Gtk::Widget *Implementation::prefs_effect(Inkscape::Extension::Effect *module, I SPDocument * current_document = view->doc(); - std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); + std::vector selected = ((SPDesktop *) view)->getSelection()->items(); Inkscape::XML::Node const* first_select = NULL; if (!selected.empty()) { const SPItem * item = selected[0]; diff --git a/src/extension/implementation/script.cpp b/src/extension/implementation/script.cpp index 01323bee2..0acc99aed 100644 --- a/src/extension/implementation/script.cpp +++ b/src/extension/implementation/script.cpp @@ -690,7 +690,7 @@ void Script::effect(Inkscape::Extension::Effect *module, } std::vector selected = - desktop->getSelection()->itemList(); //desktop should not be NULL since doc was checked and desktop is a casted pointer + desktop->getSelection()->items(); //desktop should not be NULL since doc was checked and desktop is a casted pointer for(std::vector::const_iterator x = selected.begin(); x != selected.end(); ++x){ Glib::ustring selected_id; selected_id += "--id="; diff --git a/src/extension/internal/bitmap/imagemagick.cpp b/src/extension/internal/bitmap/imagemagick.cpp index a235dcb0f..707cd763d 100644 --- a/src/extension/internal/bitmap/imagemagick.cpp +++ b/src/extension/internal/bitmap/imagemagick.cpp @@ -65,7 +65,7 @@ ImageMagickDocCache::ImageMagickDocCache(Inkscape::UI::View::View * view) : _imageItems(NULL) { SPDesktop *desktop = (SPDesktop*)view; - const std::vector selectedItemList = desktop->selection->itemList(); + const std::vector selectedItemList = desktop->selection->items(); int selectCount = selectedItemList.size(); // Init the data-holders @@ -235,7 +235,7 @@ ImageMagick::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::Vie { SPDocument * current_document = view->doc(); - std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); + std::vector selected = ((SPDesktop *) view)->getSelection()->items(); Inkscape::XML::Node * first_select = NULL; if (!selected.empty()) { first_select = (selected.front())->getRepr(); diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp index 4a04e3c33..6dc788f17 100644 --- a/src/extension/internal/bluredge.cpp +++ b/src/extension/internal/bluredge.cpp @@ -62,7 +62,7 @@ BlurEdge::effect (Inkscape::Extension::Effect *module, Inkscape::UI::View::View double old_offset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0, "px"); // TODO need to properly refcount the items, at least - std::vector items(selection->itemList()); + std::vector items(selection->items()); selection->clear(); for(std::vector::iterator item = items.begin(); diff --git a/src/extension/internal/filter/filter.cpp b/src/extension/internal/filter/filter.cpp index 25e89bbf3..acfcaed0e 100644 --- a/src/extension/internal/filter/filter.cpp +++ b/src/extension/internal/filter/filter.cpp @@ -125,7 +125,7 @@ void Filter::effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::Vie Inkscape::Selection * selection = ((SPDesktop *)document)->selection; // TODO need to properly refcount the items, at least - std::vector items(selection->itemList()); + std::vector items(selection->items()); Inkscape::XML::Document * xmldoc = document->doc()->getReprDoc(); Inkscape::XML::Node * defsrepr = document->doc()->getDefs()->getRepr(); diff --git a/src/extension/internal/grid.cpp b/src/extension/internal/grid.cpp index c766bd828..fd1b311a8 100644 --- a/src/extension/internal/grid.cpp +++ b/src/extension/internal/grid.cpp @@ -180,7 +180,7 @@ Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View { SPDocument * current_document = view->doc(); - std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); + std::vector selected = ((SPDesktop *) view)->getSelection()->items(); Inkscape::XML::Node * first_select = NULL; if (!selected.empty()) { first_select = selected[0]->getRepr(); diff --git a/src/extension/plugins/grid2/grid.cpp b/src/extension/plugins/grid2/grid.cpp index 6880c574d..c938d1ec4 100644 --- a/src/extension/plugins/grid2/grid.cpp +++ b/src/extension/plugins/grid2/grid.cpp @@ -186,7 +186,7 @@ Grid::prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View { SPDocument * current_document = view->doc(); - std::vector selected = ((SPDesktop *)view)->getSelection()->itemList(); + std::vector selected = ((SPDesktop *) view)->getSelection()->items(); Inkscape::XML::Node * first_select = NULL; if (!selected.empty()) { first_select = selected[0]->getRepr(); diff --git a/src/gradient-chemistry.cpp b/src/gradient-chemistry.cpp index edeb523d7..698cf5012 100644 --- a/src/gradient-chemistry.cpp +++ b/src/gradient-chemistry.cpp @@ -1570,7 +1570,7 @@ void sp_gradient_invert_selected_gradients(SPDesktop *desktop, Inkscape::PaintTa { Inkscape::Selection *selection = desktop->getSelection(); - const std::vector list=selection->itemList(); + const std::vector list= selection->items(); for (std::vector::const_iterator i = list.begin(); i != list.end(); ++i) { sp_item_gradient_invert_vector_color(*i, fill_or_stroke); } @@ -1595,7 +1595,7 @@ void sp_gradient_reverse_selected_gradients(SPDesktop *desktop) if (drag && !drag->selected.empty()) { drag->selected_reverse_vector(); } else { // If no drag or no dragger selected, act on selection (both fill and stroke gradients) - const std::vector list=selection->itemList(); + const std::vector list= selection->items(); for (std::vector::const_iterator i = list.begin(); i != list.end(); ++i) { sp_item_gradient_reverse_vector(*i, Inkscape::FOR_FILL); sp_item_gradient_reverse_vector(*i, Inkscape::FOR_STROKE); diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 613dc2fc1..3d1cefd4f 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -2070,7 +2070,7 @@ void GrDrag::updateDraggers() this->draggers.clear(); g_return_if_fail(this->selection != NULL); - std::vector list = this->selection->itemList(); + std::vector list = this->selection->items(); for (std::vector::const_iterator i = list.begin(); i != list.end(); ++i) { SPItem *item = *i; SPStyle *style = item->style; @@ -2138,7 +2138,7 @@ void GrDrag::updateLines() g_return_if_fail(this->selection != NULL); - std::vector list = this->selection->itemList(); + std::vector list = this->selection->items(); for (std::vector::const_iterator i = list.begin(); i != list.end(); ++i) { SPItem *item = *i; @@ -2282,7 +2282,7 @@ void GrDrag::updateLevels() g_return_if_fail (this->selection != NULL); - std::vector list = this->selection->itemList(); + std::vector list = this->selection->items(); for (std::vector::const_iterator i = list.begin(); i != list.end(); ++i) { SPItem *item = *i; Geom::OptRect rect = item->desktopVisualBounds(); diff --git a/src/object-set.cpp b/src/object-set.cpp index d282e7894..627544a21 100644 --- a/src/object-set.cpp +++ b/src/object-set.cpp @@ -16,6 +16,7 @@ #include "persp3d.h" #include "preferences.h" +namespace Inkscape { bool ObjectSet::add(SPObject* object) { g_return_val_if_fail(object != NULL, false); @@ -202,7 +203,7 @@ SPItem *ObjectSet::largestItem(CompareSize compare) { } SPItem *ObjectSet::_sizeistItem(bool sml, CompareSize compare) { - std::vector const items = itemList(); + std::vector const items = const_cast(this)->items(); gdouble max = sml ? 1e18 : 0; SPItem *ist = NULL; @@ -226,10 +227,10 @@ SPItem *ObjectSet::_sizeistItem(bool sml, CompareSize compare) { return ist; } -SPObjectRange ObjectSet::range() { +SPObjectRange ObjectSet::objects() { return SPObjectRange(container.get().begin(), container.get().end()); } -std::vector ObjectSet::itemList() { +std::vector ObjectSet::items() { std::vector tmp = std::vector(container.begin(), container.end()); std::vector result; std::remove_if(tmp.begin(), tmp.end(), [](SPObject* o){return !SP_IS_ITEM(o);}); @@ -237,6 +238,18 @@ std::vector ObjectSet::itemList() { return result; } +std::vector ObjectSet::xmlNodes() { + std::vector list = items(); + std::vector result; + std::transform(list.begin(), list.end(), std::back_inserter(result), [](SPItem* item) { return item->getRepr(); }); + return result; +} + +Inkscape::XML::Node *ObjectSet::singleRepr() { + SPObject *obj = single(); + return obj ? obj->getRepr() : nullptr; +} + void ObjectSet::set(SPObject *object) { _clear(); _add(object); @@ -273,7 +286,7 @@ Geom::OptRect ObjectSet::bounds(SPItem::BBoxType type) const Geom::OptRect ObjectSet::geometricBounds() const { - std::vector const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->items(); Geom::OptRect bbox; for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { @@ -284,7 +297,7 @@ Geom::OptRect ObjectSet::geometricBounds() const Geom::OptRect ObjectSet::visualBounds() const { - std::vector const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->items(); Geom::OptRect bbox; for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { @@ -305,7 +318,7 @@ Geom::OptRect ObjectSet::preferredBounds() const Geom::OptRect ObjectSet::documentBounds(SPItem::BBoxType type) const { Geom::OptRect bbox; - std::vector const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->items(); if (items.empty()) return bbox; for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { @@ -319,7 +332,7 @@ Geom::OptRect ObjectSet::documentBounds(SPItem::BBoxType type) const // If we have a selection of multiple items, then the center of the first item // will be returned; this is also the case in SelTrans::centerRequest() boost::optional ObjectSet::center() const { - std::vector const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->items(); if (!items.empty()) { SPItem *first = items.back(); // from the first item in selection if (first->isCenterSet()) { // only if set explicitly @@ -381,4 +394,6 @@ void ObjectSet::_remove_3D_boxes_recursively(SPObject *obj) { } _3dboxes.erase(b); } -} \ No newline at end of file +} + +} // namespace Inkscape diff --git a/src/object-set.h b/src/object-set.h index 05264a3ea..49a875562 100644 --- a/src/object-set.h +++ b/src/object-set.h @@ -28,6 +28,12 @@ class SPBox3D; class Persp3D; +namespace Inkscape { + +namespace XML { +class Node; +} + struct hashed{}; struct random_access{}; @@ -54,6 +60,12 @@ typedef boost::any_range< SPItem* const&, std::ptrdiff_t> SPItemRange; +typedef boost::any_range< + XML::Node*, + boost::random_access_traversal_tag, + XML::Node* const&, + std::ptrdiff_t> XMLNodeRange; + class ObjectSet { public: enum CompareSize {HORIZONTAL, VERTICAL, AREA}; @@ -144,10 +156,20 @@ public: SPItem *largestItem(CompareSize compare); /** Returns the list of selected objects. */ - SPObjectRange range(); + SPObjectRange objects(); /** Returns the list of selected SPItems. */ - std::vector itemList(); + std::vector items(); + + /** Returns a list of the xml nodes of all selected objects. */ + std::vector xmlNodes(); + + /** + * Returns a single selected object's xml node. + * + * @return NULL unless exactly one object is selected + */ + XML::Node *singleRepr(); /** * Selects exactly the specified objects. @@ -213,5 +235,6 @@ protected: }; +} // namespace Inkscape #endif //INKSCAPE_PROTOTYPE_OBJECTSET_H diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 1a345b565..37d242b6b 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -57,7 +57,7 @@ sp_selected_path_combine(SPDesktop *desktop, bool skip_undo) Inkscape::Selection *selection = desktop->getSelection(); SPDocument *doc = desktop->getDocument(); - std::vector items(selection->itemList()); + std::vector items(selection->items()); if (items.size() < 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to combine.")); @@ -203,7 +203,7 @@ sp_selected_path_break_apart(SPDesktop *desktop, bool skip_undo) bool did = false; - std::vector itemlist(selection->itemList()); + std::vector itemlist(selection->items()); for (std::vector::const_iterator i = itemlist.begin(); i != itemlist.end(); ++i){ SPItem *item = *i; @@ -303,7 +303,7 @@ sp_selected_path_to_curves(Inkscape::Selection *selection, SPDesktop *desktop, b desktop->setWaitingCursor(); } - std::vector selected(selection->itemList()); + std::vector selected(selection->items()); std::vector to_select; selection->clear(); std::vector items(selected); @@ -334,7 +334,7 @@ void sp_selected_to_lpeitems(SPDesktop *desktop) return; } - std::vector selected(selection->itemList()); + std::vector selected(selection->items()); std::vector to_select; selection->clear(); std::vector items(selected); @@ -603,7 +603,7 @@ void sp_selected_path_reverse(SPDesktop *desktop) { Inkscape::Selection *selection = desktop->getSelection(); - std::vector items = selection->itemList(); + std::vector items = selection->items(); if (items.empty()) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select path(s) to reverse.")); diff --git a/src/selcue.cpp b/src/selcue.cpp index 297b9fffc..13248a553 100644 --- a/src/selcue.cpp +++ b/src/selcue.cpp @@ -96,14 +96,14 @@ void Inkscape::SelCue::_updateItemBboxes(Inkscape::Preferences *prefs) void Inkscape::SelCue::_updateItemBboxes(gint mode, int prefs_bbox) { - const std::vector items = _selection->itemList(); + const std::vector items = _selection->items(); if (_item_bboxes.size() != items.size()) { _newItemBboxes(); return; } int bcount = 0; - std::vector ll=_selection->itemList(); + std::vector ll= _selection->items(); for (std::vector::const_iterator l = ll.begin(); l != ll.end(); ++l) { SPItem *item = *l; SPCanvasItem* box = _item_bboxes[bcount ++]; @@ -146,7 +146,7 @@ void Inkscape::SelCue::_newItemBboxes() int prefs_bbox = prefs->getBool("/tools/bounding_box"); - std::vector ll=_selection->itemList(); + std::vector ll= _selection->items(); for (std::vector::const_iterator l = ll.begin(); l != ll.end(); ++l) { SPItem *item = *l; @@ -201,7 +201,7 @@ void Inkscape::SelCue::_newTextBaselines() } _text_baselines.clear(); - std::vector ll = _selection->itemList(); + std::vector ll = _selection->items(); for (std::vector::const_iterator l=ll.begin();l!=ll.end();++l) { SPItem *item = *l; diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index a13f3e64d..ded776fea 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -282,7 +282,7 @@ void SelectionHelper::fixSelection(SPDesktop *dt) std::vector items ; - std::vector const selList = selection->itemList(); + std::vector const selList = selection->items(); for( std::vector::const_reverse_iterator i = selList.rbegin(); i != selList.rend(); ++i ) { SPItem *item = *i; @@ -409,7 +409,7 @@ void sp_selection_delete(SPDesktop *desktop) desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing was deleted.")); return; } - std::vector selected(selection->itemList()); + std::vector selected(selection->items()); selection->clear(); sp_selection_delete_impl(selected); desktop->currentLayer()->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); @@ -454,7 +454,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone, bool duplicat desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to duplicate.")); return; } - std::vector reprs(selection->reprList()); + std::vector reprs(selection->xmlNodes()); if(duplicateLayer){ reprs.clear(); @@ -624,7 +624,7 @@ static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool i std::vector exclude; if (invert) { - exclude = selection->itemList(); + exclude = selection->items(); } if (force_all_layers) @@ -763,7 +763,7 @@ void sp_selection_group(Inkscape::Selection *selection, SPDesktop *desktop) return; } - std::vector p (selection->reprList()); + std::vector p (selection->xmlNodes()); selection->clear(); @@ -798,7 +798,7 @@ void sp_selection_ungroup_pop_selection(Inkscape::Selection *selection, SPDeskto selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("No objects selected to pop out of group.")); return; } - std::vector selection_list = selection->itemList(); + std::vector selection_list = selection->items(); std::vector::const_iterator item = selection_list.begin(); // leaving this because it will be useful for // future implementation of complex pop ungrouping @@ -831,7 +831,7 @@ void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop) } // first check whether there is anything to ungroup - std::vector old_select = selection->itemList(); + std::vector old_select = selection->items(); std::vector new_select; GSList *groups = NULL; for (std::vector::const_iterator item = old_select.begin(); item!=old_select.end(); ++item) { @@ -983,7 +983,7 @@ bool sp_item_repr_compare_position_bool(SPObject const *first, SPObject const *s void sp_selection_raise(Inkscape::Selection *selection, SPDesktop *desktop) { - std::vector items= selection->itemList(); + std::vector items= selection->items(); if (items.empty()) { selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select object(s) to raise.")); return; @@ -1040,7 +1040,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto return; } - std::vector items = selection->itemList(); + std::vector items = selection->items(); SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { @@ -1048,7 +1048,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto return; } - std::vector rl(selection->reprList()); + std::vector rl(selection->xmlNodes()); sort(rl.begin(),rl.end(),sp_repr_compare_position_bool); for (std::vector::const_iterator l=rl.begin(); l!=rl.end();++l) { @@ -1062,7 +1062,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto void sp_selection_lower(Inkscape::Selection *selection, SPDesktop *desktop) { - std::vector items = selection->itemList(); + std::vector items = selection->items(); if (items.empty()) { selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("Select object(s) to lower.")); return; @@ -1124,7 +1124,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des return; } - std::vector items =selection->itemList(); + std::vector items = selection->items(); SPGroup const *group = sp_item_list_common_parent_group(items); if (!group) { @@ -1132,7 +1132,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des return; } - std::vector rl(selection->reprList()); + std::vector rl(selection->xmlNodes()); sort(rl.begin(),rl.end(),sp_repr_compare_position_bool); for (std::vector::const_reverse_iterator l=rl.rbegin();l!=rl.rend();++l) { @@ -1287,7 +1287,7 @@ void sp_selection_remove_livepatheffect(SPDesktop *desktop) desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to remove live path effects from.")); return; } - std::vector list=selection->itemList(); + std::vector list= selection->items(); for ( std::vector::const_iterator itemlist=list.begin();itemlist!=list.end();++itemlist) { SPItem *item = *itemlist; @@ -1368,7 +1368,7 @@ void sp_selection_to_next_layer(SPDesktop *dt, bool suppressDone) return; } - std::vector items(selection->itemList()); + std::vector items(selection->items()); bool no_more = false; // Set to true, if no more layers above SPObject *next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); @@ -1412,7 +1412,7 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) return; } - const std::vector items(selection->itemList()); + const std::vector items(selection->items()); bool no_more = false; // Set to true, if no more layers below SPObject *next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); @@ -1455,7 +1455,7 @@ void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) return; } - std::vector items(selection->itemList()); + std::vector items(selection->items()); if (moveto) { selection->clear(); @@ -1506,7 +1506,7 @@ static bool selection_contains_both_clone_and_original(Inkscape::Selection *selection) { bool clone_with_original = false; - std::vector items = selection->itemList(); + std::vector items = selection->items(); for (std::vector::const_iterator l=items.begin();l!=items.end() ;++l) { SPItem *item = *l; if (item) { @@ -1551,7 +1551,7 @@ void sp_selection_apply_affine(Inkscape::Selection *selection, Geom::Affine cons persp3d_apply_affine_transformation(transf_persp, affine); } - std::vector items = selection->itemList(); + std::vector items = selection->items(); for (std::vector::const_iterator l=items.begin();l!=items.end() ;++l) { SPItem *item = *l; @@ -1722,7 +1722,7 @@ void sp_selection_remove_transform(SPDesktop *desktop) Inkscape::Selection *selection = desktop->getSelection(); - std::vector items = selection->reprList(); + std::vector items = selection->xmlNodes(); for (std::vector::const_iterator l=items.begin();l!=items.end() ;++l) { (*l)->setAttribute("transform", NULL, false); } @@ -1822,7 +1822,7 @@ void sp_selection_rotate_90(SPDesktop *desktop, bool ccw) if (selection->isEmpty()) return; - std::vector items = selection->itemList(); + std::vector items = selection->items(); Geom::Rotate const rot_90(Geom::Point(0, ccw ? 1 : -1)); // pos. or neg. rotation, depending on the value of ccw for (std::vector::const_iterator l=items.begin();l!=items.end() ;++l) { SPItem *item = *l; @@ -1886,7 +1886,7 @@ void sp_select_same_fill_stroke_style(SPDesktop *desktop, gboolean fill, gboolea std::vector all_matches; Inkscape::Selection *selection = desktop->getSelection(); - std::vector items = selection->itemList(); + std::vector items = selection->items(); std::vector tmp; for (std::vector::const_iterator iter=all_list.begin();iter!=all_list.end();++iter) { @@ -1943,7 +1943,7 @@ void sp_select_same_object_type(SPDesktop *desktop) Inkscape::Selection *selection = desktop->getSelection(); - std::vector items=selection->itemList(); + std::vector items= selection->items(); for (std::vector::const_iterator sel_iter=items.begin();sel_iter!=items.end();++sel_iter) { SPItem *sel = *sel_iter; if (sel) { @@ -2456,7 +2456,7 @@ sp_selection_item_next(SPDesktop *desktop) root = desktop->currentRoot(); } - SPItem *item=next_item_from_list(desktop, selection->itemList(), root, SP_CYCLING == SP_CYCLE_VISIBLE, inlayer, onlyvisible, onlysensitive); + SPItem *item=next_item_from_list(desktop, selection->items(), root, SP_CYCLING == SP_CYCLE_VISIBLE, inlayer, onlyvisible, onlysensitive); if (item) { selection->set(item, PREFS_SELECTION_LAYER_RECURSIVE == inlayer); @@ -2486,7 +2486,7 @@ sp_selection_item_prev(SPDesktop *desktop) root = desktop->currentRoot(); } - SPItem *item=next_item_from_list(desktop, selection->itemList(), root, SP_CYCLING == SP_CYCLE_VISIBLE, inlayer, onlyvisible, onlysensitive); + SPItem *item=next_item_from_list(desktop, selection->items(), root, SP_CYCLING == SP_CYCLE_VISIBLE, inlayer, onlyvisible, onlysensitive); if (item) { selection->set(item, PREFS_SELECTION_LAYER_RECURSIVE == inlayer); @@ -2603,7 +2603,7 @@ void sp_selection_clone(SPDesktop *desktop) return; } - std::vector reprs (selection->reprList()); + std::vector reprs (selection->xmlNodes()); selection->clear(); @@ -2662,7 +2662,7 @@ sp_selection_relink(SPDesktop *desktop) // Get a copy of current selection. bool relinked = false; - std::vector items=selection->itemList(); + std::vector items= selection->items(); for (std::vector::const_iterator i=items.begin();i!=items.end();++i){ SPItem *item = *i; @@ -2700,7 +2700,7 @@ sp_selection_unlink(SPDesktop *desktop) // Get a copy of current selection. std::vector new_select; bool unlinked = false; - std::vector items=selection->itemList(); + std::vector items= selection->items(); for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){ SPItem *item = *i; @@ -2767,7 +2767,7 @@ sp_select_clone_original(SPDesktop *desktop) // Check if other than two objects are selected - std::vector items=selection->itemList(); + std::vector items= selection->items(); if (items.size() != 1 || !item) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, error); return; @@ -2865,7 +2865,7 @@ void sp_selection_clone_original_path_lpe(SPDesktop *desktop) Inkscape::SVGOStringStream os; SPObject * firstItem = NULL; - std::vector items=selection->itemList(); + std::vector items= selection->items(); for (std::vector::const_iterator i=items.begin();i!=items.end();++i){ if (SP_IS_SHAPE(*i) || SP_IS_TEXT(*i)) { if (firstItem) { @@ -2950,7 +2950,7 @@ void sp_selection_to_marker(SPDesktop *desktop, bool apply) Geom::Point center( *c - corner ); // As defined by rotation center center[Geom::Y] = -center[Geom::Y]; - std::vector items(selection->itemList()); + std::vector items(selection->items()); //items = g_slist_sort(items, (GCompareFunc) sp_object_compare_position); // Why needed? @@ -3024,7 +3024,7 @@ void sp_selection_to_guides(SPDesktop *desktop) SPDocument *doc = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); // we need to copy the list because it gets reset when objects are deleted - std::vector items(selection->itemList()); + std::vector items(selection->items()); if (items.empty()) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to convert to guides.")); @@ -3090,7 +3090,7 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) doc->ensureUpToDate(); - std::vector items(selection->range().begin(), selection->range().end()); + std::vector items(selection->objects().begin(), selection->objects().end()); sort(items.begin(),items.end(),sp_object_compare_position_bool); // Keep track of parent, this is where will be inserted. @@ -3302,7 +3302,7 @@ sp_selection_tile(SPDesktop *desktop, bool apply) move_p[Geom::Y] = -move_p[Geom::Y]; Geom::Affine move = Geom::Affine(Geom::Translate(move_p)); - std::vector items (selection->itemList()); + std::vector items (selection->items()); sort(items.begin(),items.end(),sp_object_compare_position_bool); @@ -3407,7 +3407,7 @@ void sp_selection_untile(SPDesktop *desktop) bool did = false; - std::vector items(selection->itemList()); + std::vector items(selection->items()); for (std::vector::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){ SPItem *item = *i; @@ -3472,7 +3472,7 @@ void sp_selection_get_export_hints(Inkscape::Selection *selection, Glib::ustring return; } - std::vector const reprlst = selection->reprList(); + std::vector const reprlst = selection->xmlNodes(); bool filename_search = TRUE; bool xdpi_search = TRUE; bool ydpi_search = TRUE; @@ -3564,7 +3564,7 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) } // List of the items to show; all others will be hidden - std::vector items(selection->itemList()); + std::vector items(selection->items()); // Sort items so that the topmost comes last sort(items.begin(),items.end(),sp_item_repr_compare_position_bool); @@ -3765,7 +3765,7 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) return; } - std::vector p(selection->reprList()); + std::vector p(selection->xmlNodes()); sort(p.begin(),p.end(),sp_repr_compare_position_bool); @@ -3875,7 +3875,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ if ( apply_to_layer && is_empty) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to create clippath or mask from.")); return; - } else if (!apply_to_layer && ( is_empty || selection->itemList().size()==1 )) { + } else if (!apply_to_layer && ( is_empty || selection->items().size()==1 )) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select mask object and object(s) to apply clippath or mask to.")); return; } @@ -3890,7 +3890,7 @@ void sp_selection_set_mask(SPDesktop *desktop, bool apply_clip_path, bool apply_ doc->ensureUpToDate(); - std::vector items(selection->itemList()); + std::vector items(selection->items()); sort(items.begin(),items.end(),sp_object_compare_position_bool); @@ -4052,7 +4052,7 @@ void sp_selection_unset_mask(SPDesktop *desktop, bool apply_clip_path) { gchar const *attributeName = apply_clip_path ? "clip-path" : "mask"; std::map referenced_objects; - std::vector items(selection->itemList()); + std::vector items(selection->items()); selection->clear(); GSList *items_to_ungroup = NULL; diff --git a/src/selection-describer.cpp b/src/selection-describer.cpp index ddc7a0d10..93808ed54 100644 --- a/src/selection-describer.cpp +++ b/src/selection-describer.cpp @@ -122,7 +122,7 @@ void SelectionDescriber::_selectionModified(Inkscape::Selection *selection, guin } void SelectionDescriber::_updateMessageFromSelection(Inkscape::Selection *selection) { - std::vector const items = selection->itemList(); + std::vector const items = selection->items(); if (items.empty()) { // no items _context.set(Inkscape::NORMAL_MESSAGE, _when_nothing); diff --git a/src/selection.cpp b/src/selection.cpp index 32e27f2d4..94b64a7bc 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -130,25 +130,13 @@ void Selection::setReprList(std::vector const &list) { _emitChanged(); } -std::vector Selection::reprList() { - std::vector list = itemList(); - std::vector result; - std::transform(list.begin(), list.end(), std::back_inserter(result), [](SPItem* item) { return item->getRepr(); }); - return result; -} - -Inkscape::XML::Node *Selection::singleRepr() { - SPObject *obj = single(); - return obj ? obj->getRepr() : nullptr; -} - std::vector Selection::getSnapPoints(SnapPreferences const *snapprefs) const { std::vector p; if (snapprefs != NULL){ SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, false); // locally disable snapping to the item center - std::vector const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->items(); for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPItem *this_item = *iter; this_item->getSnappoints(p, &snapprefs_dummy); @@ -174,7 +162,7 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { } size_t Selection::numberOfLayers() { - std::vector const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->items(); std::set layers; for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPObject *layer = _layers->layerForObject(*iter); @@ -185,7 +173,7 @@ size_t Selection::numberOfLayers() { } size_t Selection::numberOfParents() { - std::vector const items = const_cast(this)->itemList(); + std::vector const items = const_cast(this)->items(); std::set parents; for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPObject *parent = (*iter)->parent; diff --git a/src/selection.h b/src/selection.h index 8b1bb25fa..7027a388f 100644 --- a/src/selection.h +++ b/src/selection.h @@ -39,12 +39,6 @@ class Node; namespace Inkscape { -typedef boost::any_range< - XML::Node*, - boost::random_access_traversal_tag, - XML::Node* const&, - std::ptrdiff_t> XMLNodeRange; - /** * The set of selected SPObjects for a given document and layer model. * @@ -156,16 +150,6 @@ public: return includes(_objectForXMLNode(repr)); } - /** - * Returns a single selected object's xml node. - * - * @return NULL unless exactly one object is selected - */ - XML::Node *singleRepr(); - - /** Returns a list of the xml nodes of all selected objects. */ - std::vector reprList(); - /** Returns the number of layers in which there are selected objects. */ size_t numberOfLayers(); diff --git a/src/seltrans.cpp b/src/seltrans.cpp index b54525610..9fa6172ed 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -240,7 +240,7 @@ void Inkscape::SelTrans::setCenter(Geom::Point const &p) _center_is_set = true; // Write the new center position into all selected items - std::vector items=_desktop->selection->itemList(); + std::vector items= _desktop->selection->items(); for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPItem *it = SP_ITEM(*iter); it->setCenter(p); @@ -270,7 +270,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s return; } - std::vector items=_desktop->selection->itemList(); + std::vector items= _desktop->selection->items(); for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPItem *it = static_cast(sp_object_ref(*iter, NULL)); _items.push_back(it); @@ -492,7 +492,7 @@ void Inkscape::SelTrans::ungrab() if (_center_is_set) { // we were dragging center; update reprs and commit undoable action - std::vector items=_desktop->selection->itemList(); + std::vector items= _desktop->selection->items(); for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPItem *it = *iter; it->updateRepr(); @@ -529,7 +529,7 @@ void Inkscape::SelTrans::stamp() l = _stamp_cache; } else { /* Build cache */ - l = selection->itemList(); + l = selection->items(); sort(l.begin(),l.end(),sp_object_compare_position_bool); _stamp_cache = l; } @@ -621,7 +621,7 @@ void Inkscape::SelTrans::_updateVolatileState() return; } - _strokewidth = stroke_average_width (selection->itemList()); + _strokewidth = stroke_average_width (selection->items()); } void Inkscape::SelTrans::_showHandles(SPSelTransType type) @@ -711,7 +711,7 @@ void Inkscape::SelTrans::handleClick(SPKnot */*knot*/, guint state, SPSelTransHa case HANDLE_CENTER: if (state & GDK_SHIFT_MASK) { // Unset the center position for all selected items - std::vector items=_desktop->selection->itemList(); + std::vector items= _desktop->selection->items(); for ( std::vector::const_iterator iter=items.begin();iter!=items.end(); ++iter) { SPItem *it = *iter; it->unsetCenter(); @@ -1287,7 +1287,7 @@ gboolean Inkscape::SelTrans::centerRequest(Geom::Point &pt, guint state) // items will share a single center. While dragging that single center, it should never snap to the // centers of any of the selected objects. Therefore we will have to pass the list of selected items // to the snapper, to avoid self-snapping of the rotation center - std::vector items = const_cast(_selection)->itemList(); + std::vector items = const_cast(_selection)->items(); SnapManager &m = _desktop->namedview->snap_manager; m.setup(_desktop); m.setRotationCenterSource(items); diff --git a/src/snap.cpp b/src/snap.cpp index 7f0e8d9dc..d1d15ca0c 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -708,7 +708,7 @@ void SnapManager::setupIgnoreSelection(SPDesktop const *desktop, _items_to_ignore.clear(); Inkscape::Selection *sel = _desktop->selection; - std::vector const items = sel->itemList(); + std::vector const items = sel->items(); for (std::vector::const_iterator i=items.begin();i!=items.end();++i) { _items_to_ignore.push_back(*i); } diff --git a/src/splivarot.cpp b/src/splivarot.cpp index 1bc6da3e1..d4ef3f9c2 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -335,7 +335,7 @@ void sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool_op bop, const unsigned int verb, const Glib::ustring description) { SPDocument *doc = selection->layers()->getDocument(); - std::vector il= selection->itemList(); + std::vector il= selection->items(); // allow union on a single object for the purpose of removing self overlapse (svn log, revision 13334) if ( (il.size() < 2) && (bop != bool_op_union)) { @@ -689,7 +689,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool } } else { // find out the bottom object - std::vector sorted(selection->reprList()); + std::vector sorted(selection->xmlNodes()); sort(sorted.begin(),sorted.end(),sp_repr_compare_position_bool); @@ -1157,7 +1157,7 @@ sp_selected_path_outline(SPDesktop *desktop) bool scale_stroke = prefs->getBool("/options/transform/stroke", true); prefs->setBool("/options/transform/stroke", true); bool did = false; - std::vector il(selection->itemList()); + std::vector il(selection->items()); for (std::vector::const_iterator l = il.begin(); l != il.end(); l++){ SPItem *item = *l; @@ -1771,7 +1771,7 @@ sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) } bool did = false; - std::vector il(selection->itemList()); + std::vector il(selection->items()); for (std::vector::const_iterator l = il.begin(); l != il.end(); l++){ SPItem *item = *l; SPCurve *curve = NULL; @@ -2196,7 +2196,7 @@ sp_selected_path_simplify_selection(SPDesktop *desktop, float threshold, bool ju return; } - std::vector items(selection->itemList()); + std::vector items(selection->items()); bool didSomething = sp_selected_path_simplify_items(desktop, selection, items, threshold, diff --git a/src/text-chemistry.cpp b/src/text-chemistry.cpp index fbbbe5807..5565464a1 100644 --- a/src/text-chemistry.cpp +++ b/src/text-chemistry.cpp @@ -43,7 +43,7 @@ using Inkscape::DocumentUndo; static SPItem * flowtext_in_selection(Inkscape::Selection *selection) { - std::vector items = selection->itemList(); + std::vector items = selection->items(); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ if (SP_IS_FLOWTEXT(*i)) return *i; @@ -54,7 +54,7 @@ flowtext_in_selection(Inkscape::Selection *selection) static SPItem * text_or_flowtext_in_selection(Inkscape::Selection *selection) { - std::vector items = selection->itemList(); + std::vector items = selection->items(); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) return *i; @@ -65,7 +65,7 @@ text_or_flowtext_in_selection(Inkscape::Selection *selection) static SPItem * shape_in_selection(Inkscape::Selection *selection) { - std::vector items = selection->itemList(); + std::vector items = selection->items(); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ if (SP_IS_SHAPE(*i)) return *i; @@ -87,7 +87,7 @@ text_put_on_path() Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); - if (!text || !shape || selection->itemList().size() != 2) { + if (!text || !shape || selection->items().size() != 2) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a text and a path to put text on path.")); return; } @@ -196,7 +196,7 @@ text_remove_from_path() } bool did = false; - std::vector items(selection->itemList()); + std::vector items(selection->items()); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ SPObject *obj = *i; @@ -214,7 +214,7 @@ text_remove_from_path() } else { DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_TEXT, _("Remove text from path")); - selection->setList(selection->itemList()); // reselect to update statusbar description + selection->setList(selection->items()); // reselect to update statusbar description } } @@ -260,7 +260,7 @@ text_remove_all_kerns() bool did = false; - std::vector items = selection->itemList(); + std::vector items = selection->items(); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ SPObject *obj = *i; @@ -296,7 +296,7 @@ text_flow_into_shape() SPItem *text = text_or_flowtext_in_selection(selection); SPItem *shape = shape_in_selection(selection); - if (!text || !shape || selection->itemList().size() < 2) { + if (!text || !shape || selection->items().size() < 2) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a text and one or more paths or shapes to flow text into frame.")); return; } @@ -320,7 +320,7 @@ text_flow_into_shape() g_return_if_fail(SP_IS_FLOWREGION(object)); /* Add clones */ - std::vector items = selection->itemList(); + std::vector items = selection->items(); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ SPItem *item = *i; if (SP_IS_SHAPE(item)){ @@ -387,7 +387,7 @@ text_unflow () Inkscape::Selection *selection = desktop->getSelection(); - if (!flowtext_in_selection(selection) || selection->itemList().size() < 1) { + if (!flowtext_in_selection(selection) || selection->items().size() < 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a flowed text to unflow it.")); return; } @@ -395,7 +395,7 @@ text_unflow () std::vector new_objs; GSList *old_objs = NULL; - std::vector items = selection->itemList(); + std::vector items = selection->items(); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ if (!SP_IS_FLOWTEXT(*i)) { @@ -480,7 +480,7 @@ flowtext_to_text() bool did = false; std::vector reprs; - std::vector items(selection->itemList()); + std::vector items(selection->items()); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ SPItem *item = *i; diff --git a/src/trace/trace.cpp b/src/trace/trace.cpp index 379682668..f0fa61b89 100644 --- a/src/trace/trace.cpp +++ b/src/trace/trace.cpp @@ -65,7 +65,7 @@ SPImage *Tracer::getSelectedSPImage() if (sioxEnabled) { SPImage *img = NULL; - std::vector const list = sel->itemList(); + std::vector const list = sel->items(); std::vector items; sioxShapes.clear(); diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index d581dbf7e..b1a946db2 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -522,7 +522,7 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a // resize each object in the selection if (separately) { - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (item) { @@ -578,7 +578,7 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) desktop->doc()->importDefs(tempdoc); // make sure all selected items are converted to paths first (i.e. rectangles) sp_selected_to_lpeitems(desktop); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; _applyPathEffect(item, effectstack); @@ -661,7 +661,7 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop) void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) { // copy the defs used by all items - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); cloned_elements.clear(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index 8f87932b8..b7b5b96cd 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -133,7 +133,7 @@ void ActionAlign::do_action(SPDesktop *desktop, int index) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool sel_as_group = prefs->getBool("/dialogs/align/sel-as-groups"); - std::vector selected(selection->itemList()); + std::vector selected(selection->items()); if (selected.empty()) return; const Coeffs &a = _allCoeffs[index]; @@ -293,7 +293,7 @@ private : Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; - std::vector selected(selection->itemList()); + std::vector selected(selection->items()); if (selected.empty()) return; //Check 2 or more selected objects @@ -499,7 +499,7 @@ private : // xGap and yGap are the minimum space required between bounding rectangles. double const xGap = removeOverlapXGap.get_value(); double const yGap = removeOverlapYGap.get_value(); - removeoverlap(_dialog.getDesktop()->getSelection()->itemList(), xGap, yGap); + removeoverlap(_dialog.getDesktop()->getSelection()->items(), xGap, yGap); // restore compensation setting prefs->setInt("/options/clonecompensation/value", saved_compensation); @@ -530,7 +530,7 @@ private : int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - graphlayout(_dialog.getDesktop()->getSelection()->itemList()); + graphlayout(_dialog.getDesktop()->getSelection()->items()); // restore compensation setting prefs->setInt("/options/clonecompensation/value", saved_compensation); @@ -590,7 +590,7 @@ private : Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; - std::vector selected(selection->itemList()); + std::vector selected(selection->items()); if (selected.empty()) return; //Check 2 or more selected objects @@ -656,7 +656,7 @@ private : Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - std::vector x(_dialog.getDesktop()->getSelection()->itemList()); + std::vector x(_dialog.getDesktop()->getSelection()->items()); unclump (x); // restore compensation setting @@ -687,7 +687,7 @@ private : Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; - std::vector selected(selection->itemList()); + std::vector selected(selection->items()); if (selected.empty()) return; //Check 2 or more selected objects @@ -785,7 +785,7 @@ private : Inkscape::Selection *selection = desktop->getSelection(); if (!selection) return; - std::vector selected(selection->itemList()); + std::vector selected(selection->items()); //Check 2 or more selected objects if (selected.size() < 2) return; diff --git a/src/ui/dialog/clonetiler.cpp b/src/ui/dialog/clonetiler.cpp index b727c87ee..7ce937de7 100644 --- a/src/ui/dialog/clonetiler.cpp +++ b/src/ui/dialog/clonetiler.cpp @@ -1376,7 +1376,7 @@ void CloneTiler::clonetiler_change_selection(Inkscape::Selection *selection, Gtk return; } - if (selection->itemList().size() > 1) { + if (selection->items().size() > 1) { gtk_widget_set_sensitive (buttons, FALSE); gtk_label_set_markup (GTK_LABEL(status), _("More than one object selected.")); return; @@ -2113,7 +2113,7 @@ void CloneTiler::clonetiler_unclump(GtkWidget */*widget*/, void *) Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected - if (selection->isEmpty() || selection->itemList().size() > 1) { + if (selection->isEmpty() || selection->items().size() > 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select one object whose tiled clones to unclump.")); return; } @@ -2162,7 +2162,7 @@ void CloneTiler::clonetiler_remove(GtkWidget */*widget*/, GtkWidget *dlg, bool d Inkscape::Selection *selection = desktop->getSelection(); // check if something is selected - if (selection->isEmpty() || selection->itemList().size() > 1) { + if (selection->isEmpty() || selection->items().size() > 1) { desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select one object whose tiled clones to remove.")); return; } @@ -2240,7 +2240,7 @@ void CloneTiler::clonetiler_apply(GtkWidget */*widget*/, GtkWidget *dlg) } // Check if more than one object is selected. - if (selection->itemList().size() > 1) { + if (selection->items().size() > 1) { desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("If you want to clone several objects, group them and clone the group.")); return; } diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 2fb5f9e3b..6d2842511 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -608,7 +608,7 @@ void Export::onBatchClicked () void Export::updateCheckbuttons () { - gint num = SP_ACTIVE_DESKTOP->getSelection()->itemList().size(); + gint num = SP_ACTIVE_DESKTOP->getSelection()->items().size(); if (num >= 2) { batch_export.set_sensitive(true); batch_export.set_label(g_strdup_printf (ngettext("B_atch export %d selected object","B_atch export %d selected objects",num), num)); @@ -820,7 +820,7 @@ void Export::onAreaToggled () one that's nice */ if (filename.empty()) { const gchar * id = "object"; - const std::vector reprlst = SP_ACTIVE_DESKTOP->getSelection()->reprList(); + const std::vector reprlst = SP_ACTIVE_DESKTOP->getSelection()->xmlNodes(); for(std::vector::const_iterator i=reprlst.begin(); reprlst.end() != i; ++i) { Inkscape::XML::Node * repr = *i; if (repr->attribute("id")) { @@ -1015,7 +1015,7 @@ void Export::onExport () if (batch_export.get_active ()) { // Batch export of selected objects - gint num = (desktop->getSelection()->itemList()).size(); + gint num = (desktop->getSelection()->items()).size(); gint n = 0; if (num < 1) { @@ -1029,7 +1029,7 @@ void Export::onExport () gint export_count = 0; - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i = itemlist.begin();i!=itemlist.end() && !interrupted ;++i){ SPItem *item = *i; @@ -1075,7 +1075,7 @@ void Export::onExport () nv->pagecolor, onProgressCallback, (void*)prog_dlg, TRUE, // overwrite without asking - hide ? (desktop->getSelection()->itemList()) : x + hide ? (desktop->getSelection()->items()) : x )) { gchar * error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); @@ -1165,7 +1165,7 @@ void Export::onExport () nv->pagecolor, onProgressCallback, (void*)prog_dlg, FALSE, - hide ? (desktop->getSelection()->itemList()) : x + hide ? (desktop->getSelection()->items()) : x ); if (status == EXPORT_ERROR) { gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str()); @@ -1237,7 +1237,7 @@ void Export::onExport () bool saved = DocumentUndo::getUndoSensitive(doc); DocumentUndo::setUndoSensitive(doc, false); - reprlst = desktop->getSelection()->reprList(); + reprlst = desktop->getSelection()->xmlNodes(); for(std::vector::const_iterator i=reprlst.begin(); reprlst.end() != i; ++i) { Inkscape::XML::Node * repr = *i; diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index d3ad5d1da..dfc19f3cc 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -691,7 +691,7 @@ private: void select_svg_element(){ Inkscape::Selection* sel = _desktop->getSelection(); if (sel->isEmpty()) return; - Inkscape::XML::Node* node = sel->reprList()[0]; + Inkscape::XML::Node* node = sel->xmlNodes()[0]; if (!node || !node->matchAttributeName("id")) return; std::ostringstream xlikhref; @@ -1474,7 +1474,7 @@ void FilterEffectsDialog::FilterModifier::update_selection(Selection *sel) } std::set used; - std::vector itemlist=sel->itemList(); + std::vector itemlist= sel->items(); for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; ++i) { SPObject *obj = *i; SPStyle *style = obj->style; @@ -1555,7 +1555,7 @@ void FilterEffectsDialog::FilterModifier::on_selection_toggled(const Glib::ustri if((*iter)[_columns.sel] == 1) filter = 0; - std::vector itemlist=sel->itemList(); + std::vector itemlist= sel->items(); for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; ++i) { SPItem * item = *i; SPStyle *style = item->style; diff --git a/src/ui/dialog/find.cpp b/src/ui/dialog/find.cpp index 0f368c5ac..8424dd7f5 100644 --- a/src/ui/dialog/find.cpp +++ b/src/ui/dialog/find.cpp @@ -761,7 +761,7 @@ std::vector &Find::all_items (SPObject *r, std::vector &l, boo std::vector &Find::all_selection_items (Inkscape::Selection *s, std::vector &l, SPObject *ancestor, bool hidden, bool locked) { - std::vector itemlist=s->itemList(); + std::vector itemlist= s->items(); for(std::vector::const_reverse_iterator i=itemlist.rbegin(); itemlist.rend() != i; ++i) { SPObject *obj = *i; SPItem *item = dynamic_cast(obj); diff --git a/src/ui/dialog/glyphs.cpp b/src/ui/dialog/glyphs.cpp index 56b001291..30b0f8df7 100644 --- a/src/ui/dialog/glyphs.cpp +++ b/src/ui/dialog/glyphs.cpp @@ -578,7 +578,7 @@ void GlyphsPanel::setTargetDesktop(SPDesktop *desktop) void GlyphsPanel::insertText() { SPItem *textItem = 0; - std::vector itemlist=targetDesktop->selection->itemList(); + std::vector itemlist= targetDesktop->selection->items(); for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; ++i) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { textItem = *i; @@ -688,7 +688,7 @@ void GlyphsPanel::selectionModifiedCB(guint flags) void GlyphsPanel::calcCanInsert() { int items = 0; - std::vector itemlist=targetDesktop->selection->itemList(); + std::vector itemlist= targetDesktop->selection->items(); for(std::vector::const_iterator i=itemlist.begin(); itemlist.end() != i; ++i) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) { ++items; diff --git a/src/ui/dialog/grid-arrange-tab.cpp b/src/ui/dialog/grid-arrange-tab.cpp index 639e463ea..ddcc20cb7 100644 --- a/src/ui/dialog/grid-arrange-tab.cpp +++ b/src/ui/dialog/grid-arrange-tab.cpp @@ -163,7 +163,7 @@ void GridArrangeTab::arrange() desktop->getDocument()->ensureUpToDate(); Inkscape::Selection *selection = desktop->getSelection(); - const std::vector items = selection ? selection->itemList() : std::vector(); + const std::vector items = selection ? selection->items() : std::vector(); for(std::vector::const_iterator i = items.begin();i!=items.end(); ++i){ SPItem *item = *i; Geom::OptRect b = item->documentVisualBounds(); @@ -192,7 +192,7 @@ void GridArrangeTab::arrange() // require the sorting done before we can calculate row heights etc. g_return_if_fail(selection); - std::vector sorted(selection->itemList()); + std::vector sorted(selection->items()); sort(sorted.begin(),sorted.end(),sp_compare_y_position); sort(sorted.begin(),sorted.end(),sp_compare_x_position); @@ -368,7 +368,7 @@ void GridArrangeTab::on_row_spinbutton_changed() Inkscape::Selection *selection = desktop ? desktop->selection : 0; g_return_if_fail( selection ); - std::vector const items = selection->itemList(); + std::vector const items = selection->items(); int selcount = items.size(); double PerCol = ceil(selcount / NoOfColsSpinner.get_value()); @@ -394,7 +394,7 @@ void GridArrangeTab::on_col_spinbutton_changed() Inkscape::Selection *selection = desktop ? desktop->selection : 0; g_return_if_fail(selection); - int selcount = selection->itemList().size(); + int selcount = selection->items().size(); double PerRow = ceil(selcount / NoOfRowsSpinner.get_value()); NoOfColsSpinner.set_value(PerRow); @@ -531,7 +531,7 @@ void GridArrangeTab::updateSelection() updating = true; SPDesktop *desktop = Parent->getDesktop(); Inkscape::Selection *selection = desktop ? desktop->selection : 0; - std::vector const items = selection ? selection->itemList() : std::vector(); + std::vector const items = selection ? selection->items() : std::vector(); if (!items.empty()) { int selcount = items.size(); @@ -602,7 +602,7 @@ GridArrangeTab::GridArrangeTab(ArrangeDialog *parent) g_return_if_fail( selection ); int selcount = 1; if (!selection->isEmpty()) { - selcount = selection->itemList().size(); + selcount = selection->items().size(); } diff --git a/src/ui/dialog/icon-preview.cpp b/src/ui/dialog/icon-preview.cpp index 83656a1f2..173a964e9 100644 --- a/src/ui/dialog/icon-preview.cpp +++ b/src/ui/dialog/icon-preview.cpp @@ -362,7 +362,7 @@ void IconPreviewPanel::refreshPreview() if ( sel ) { //g_message("found a selection to play with"); - std::vector const items = sel->itemList(); + std::vector const items = sel->items(); for(std::vector::const_iterator i=items.begin();!target && i!=items.end();++i){ SPItem* item = *i; gchar const *id = item->getId(); diff --git a/src/ui/dialog/objects.cpp b/src/ui/dialog/objects.cpp index 27694a9ac..df32f73cf 100644 --- a/src/ui/dialog/objects.cpp +++ b/src/ui/dialog/objects.cpp @@ -478,7 +478,7 @@ void ObjectsPanel::_objectsSelected( Selection *sel ) { _selectedConnection.block(); _tree.get_selection()->unselect_all(); SPItem *item = NULL; - std::vector const items = sel->itemList(); + std::vector const items = sel->items(); for(std::vector::const_iterator i=items.begin(); i!=items.end(); ++i){ item = *i; if (setOpacity) diff --git a/src/ui/dialog/pixelartdialog.cpp b/src/ui/dialog/pixelartdialog.cpp index f557ff0fc..ed62e26b0 100644 --- a/src/ui/dialog/pixelartdialog.cpp +++ b/src/ui/dialog/pixelartdialog.cpp @@ -372,7 +372,7 @@ void PixelArtDialogImpl::vectorize() return; } - std::vector const items = desktop->selection->itemList(); + std::vector const items = desktop->selection->items(); for(std::vector::const_iterator i=items.begin(); i!=items.end();++i){ if ( !SP_IS_IMAGE(*i) ) continue; diff --git a/src/ui/dialog/polar-arrange-tab.cpp b/src/ui/dialog/polar-arrange-tab.cpp index 5ec1285c1..c160c269f 100644 --- a/src/ui/dialog/polar-arrange-tab.cpp +++ b/src/ui/dialog/polar-arrange-tab.cpp @@ -297,7 +297,7 @@ static void moveToPoint(int anchor, SPItem *item, Geom::Point p) void PolarArrangeTab::arrange() { Inkscape::Selection *selection = parent->getDesktop()->getSelection(); - const std::vector tmp(selection->itemList()); + const std::vector tmp(selection->items()); SPGenericEllipse *referenceEllipse = NULL; // Last ellipse in selection bool arrangeOnEllipse = !arrangeOnParametersRadio.get_active(); diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index 790c0e5fb..100a620fa 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -524,7 +524,7 @@ void SvgFontsDialog::set_glyph_description_from_selected_path(){ return; } - Inkscape::XML::Node* node = sel->reprList().front(); + Inkscape::XML::Node* node = sel->xmlNodes().front(); if (!node) return;//TODO: should this be an assert? if (!node->matchAttributeName("d") || !node->attribute("d")){ char *msg = _("The selected object does not have a path description."); @@ -566,7 +566,7 @@ void SvgFontsDialog::missing_glyph_description_from_selected_path(){ return; } - Inkscape::XML::Node* node = sel->reprList().front(); + Inkscape::XML::Node* node = sel->xmlNodes().front(); if (!node) return;//TODO: should this be an assert? if (!node->matchAttributeName("d") || !node->attribute("d")){ char *msg = _("The selected object does not have a path description."); diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 6577c8d4e..2573719ac 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -123,7 +123,7 @@ static void editGradientImpl( SPDesktop* desktop, SPGradient* gr ) bool shown = false; if ( desktop && desktop->doc() ) { Inkscape::Selection *selection = desktop->getSelection(); - std::vector const items = selection->itemList(); + std::vector const items = selection->items(); if (!items.empty()) { SPStyle query( desktop->doc() ); int result = objects_query_fillstroke((items), &query, true); diff --git a/src/ui/dialog/tags.cpp b/src/ui/dialog/tags.cpp index affbe0a3b..98b0f9502 100644 --- a/src/ui/dialog/tags.cpp +++ b/src/ui/dialog/tags.cpp @@ -348,7 +348,7 @@ void TagsPanel::_objectsSelected( Selection *sel ) { _selectedConnection.block(); _tree.get_selection()->unselect_all(); - auto tmp = sel->range(); + auto tmp = sel->objects(); for(auto i = tmp.begin(); i != tmp.end(); ++i) { SPObject *obj = *i; @@ -646,7 +646,7 @@ bool TagsPanel::_handleButtonEvent(GdkEventButton* event) if (col == _tree.get_column(COL_ADD - 1) && down_at_add) { if (SP_IS_TAG(obj)) { bool wasadded = false; - std::vector items=_desktop->selection->itemList(); + std::vector items= _desktop->selection->items(); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ SPObject *newobj = *i; bool addchild = true; diff --git a/src/ui/dialog/text-edit.cpp b/src/ui/dialog/text-edit.cpp index c01da8864..355bd16d1 100644 --- a/src/ui/dialog/text-edit.cpp +++ b/src/ui/dialog/text-edit.cpp @@ -443,7 +443,7 @@ SPItem *TextEdit::getSelectedTextItem (void) if (!SP_ACTIVE_DESKTOP) return NULL; - std::vector tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + std::vector tmp= SP_ACTIVE_DESKTOP->getSelection()->items(); for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();++i) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) @@ -461,7 +461,7 @@ unsigned TextEdit::getSelectedTextCount (void) unsigned int items = 0; - std::vector tmp=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + std::vector tmp= SP_ACTIVE_DESKTOP->getSelection()->items(); for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();++i) { if (SP_IS_TEXT(*i) || SP_IS_FLOWTEXT(*i)) @@ -568,7 +568,7 @@ void TextEdit::onApply() SPDesktop *desktop = SP_ACTIVE_DESKTOP; unsigned items = 0; - const std::vector item_list = desktop->getSelection()->itemList(); + const std::vector item_list = desktop->getSelection()->items(); SPCSSAttr *css = fillTextStyle (); sp_desktop_set_style(desktop, css, true); diff --git a/src/ui/dialog/transformation.cpp b/src/ui/dialog/transformation.cpp index b7638e8c1..f11ac1ebe 100644 --- a/src/ui/dialog/transformation.cpp +++ b/src/ui/dialog/transformation.cpp @@ -650,7 +650,7 @@ void Transformation::updatePageTransform(Inkscape::Selection *selection) { if (selection && !selection->isEmpty()) { if (_check_replace_matrix.get_active()) { - Geom::Affine current (selection->itemList()[0]->transform); // take from the first item in selection + Geom::Affine current (selection->items()[0]->transform); // take from the first item in selection Geom::Affine new_displayed = current; @@ -735,7 +735,7 @@ void Transformation::applyPageMove(Inkscape::Selection *selection) if (_check_move_relative.get_active()) { // shift each object relatively to the previous one - std::vector selected(selection->itemList()); + std::vector selected(selection->items()); if (selected.empty()) return; if (fabs(x) > 1e-6) { @@ -810,7 +810,7 @@ void Transformation::applyPageScale(Inkscape::Selection *selection) bool transform_stroke = prefs->getBool("/options/transform/stroke", true); bool preserve = prefs->getBool("/options/preservetransform/value", false); if (prefs->getBool("/dialogs/transformation/applyseparately")) { - std::vector tmp=selection->itemList(); + std::vector tmp= selection->items(); for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();++i){ SPItem *item = *i; Geom::OptRect bbox_pref = item->desktopPreferredBounds(); @@ -874,7 +874,7 @@ void Transformation::applyPageRotate(Inkscape::Selection *selection) } if (prefs->getBool("/dialogs/transformation/applyseparately")) { - std::vector tmp=selection->itemList(); + std::vector tmp= selection->items(); for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();++i){ SPItem *item = *i; sp_item_rotate_rel(item, Geom::Rotate (angle*M_PI/180.0)); @@ -894,7 +894,7 @@ void Transformation::applyPageSkew(Inkscape::Selection *selection) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/dialogs/transformation/applyseparately")) { - std::vector items=selection->itemList(); + std::vector items= selection->items(); for(std::vector::const_iterator i = items.begin();i!=items.end();++i){ SPItem *item = *i; @@ -996,7 +996,7 @@ void Transformation::applyPageTransform(Inkscape::Selection *selection) } if (_check_replace_matrix.get_active()) { - std::vector tmp=selection->itemList(); + std::vector tmp= selection->items(); for(std::vector::const_iterator i=tmp.begin();i!=tmp.end();++i){ SPItem *item = *i; item->set_item_transform(displayed); @@ -1149,7 +1149,7 @@ void Transformation::onReplaceMatrixToggled() double f = _scalar_transform_f.getValue(); Geom::Affine displayed (a, b, c, d, e, f); - Geom::Affine current = selection->itemList()[0]->transform; // take from the first item in selection + Geom::Affine current = selection->items()[0]->transform; // take from the first item in selection Geom::Affine new_displayed; if (_check_replace_matrix.get_active()) { diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index ab29471ed..7bbf588a7 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -2096,7 +2096,7 @@ void ContextMenu::ImageEdit(void) } #endif - std::vector itemlist=_desktop->selection->itemList(); + std::vector itemlist= _desktop->selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ Inkscape::XML::Node *ir = (*i)->getRepr(); const gchar *href = ir->attribute("xlink:href"); diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index 74f2664fe..52ddd589c 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -1306,7 +1306,7 @@ void cc_selection_set_avoid(bool const set_avoid) int changes = 0; - std::vector l = selection->itemList(); + std::vector l = selection->items(); for(std::vector::const_iterator i=l.begin();i!=l.end(); ++i) { SPItem *item = *i; diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index cb7747b2b..a81161ea9 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -692,7 +692,7 @@ void EraserTool::set_to_accumulated() { } } } else { - toWorkOn = selection->itemList(); + toWorkOn = selection->items(); } wasSelection = true; } @@ -744,7 +744,7 @@ void EraserTool::set_to_accumulated() { } if ( !selection->isEmpty() ) { // If the item was not completely erased, track the new remainder. - std::vector nowSel(selection->itemList()); + std::vector nowSel(selection->items()); for (std::vector::const_iterator i2 = nowSel.begin();i2!=nowSel.end();++i2) { remainingItems.push_back(*i2); } diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index 9d8101cc4..e2bb0dc07 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -106,7 +106,7 @@ void GradientTool::selection_changed(Inkscape::Selection*) { if (selection == NULL) { return; } - guint n_obj = selection->itemList().size(); + guint n_obj = selection->items().size(); if (!drag->isNonEmpty() || selection->isEmpty()) return; @@ -492,9 +492,9 @@ bool GradientTool::root_handler(GdkEvent* event) { if (over_line) { // we take the first item in selection, because with doubleclick, the first click // always resets selection to the single object under cursor - sp_gradient_context_add_stop_near_point(this, SP_ITEM(selection->itemList().front()), this->mousepoint_doc, event->button.time); + sp_gradient_context_add_stop_near_point(this, SP_ITEM(selection->items().front()), this->mousepoint_doc, event->button.time); } else { - std::vector items=selection->itemList(); + std::vector items= selection->items(); for (std::vector::const_iterator i = items.begin();i!=items.end();++i) { SPItem *item = *i; SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR); @@ -897,7 +897,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta } else { // Starting from empty space: // Sort items so that the topmost comes last - std::vector items(selection->itemList()); + std::vector items(selection->items()); sort(items.begin(),items.end(),sp_item_repr_compare_position); // take topmost vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(items.back()), fill_or_stroke); @@ -907,7 +907,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-opacity", "1.0"); - std::vector itemlist = selection->itemList(); + std::vector itemlist = selection->items(); for (std::vector::const_iterator i = itemlist.begin();i!=itemlist.end();++i) { //FIXME: see above @@ -931,7 +931,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta ec->_grdrag->local_change = true; // give the grab out-of-bounds values of xp/yp because we're already dragging // and therefore are already out of tolerance - ec->_grdrag->grabKnot (selection->itemList()[0], + ec->_grdrag->grabKnot (selection->items()[0], type == SP_GRADIENT_TYPE_LINEAR? POINT_LG_END : POINT_RG_R1, -1, // ignore number (though it is always 1) fill_or_stroke, 99999, 99999, etime); @@ -940,7 +940,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta // status text; we do not track coords because this branch is run once, not all the time // during drag - int n_objects = selection->itemList().size(); + int n_objects = selection->items().size(); rc.message_context->setF(Inkscape::NORMAL_MESSAGE, ngettext("Gradient for %d object; with Ctrl to snap angle", "Gradient for %d objects; with Ctrl to snap angle", n_objects), diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp index 9bbc1ac20..ebcac2279 100644 --- a/src/ui/tools/lpe-tool.cpp +++ b/src/ui/tools/lpe-tool.cpp @@ -396,7 +396,7 @@ lpetool_create_measuring_items(LpeTool *lc, Inkscape::Selection *selection) SPCanvasGroup *tmpgrp = lc->desktop->getTempGroup(); gchar *arc_length; double lengthval; - std::vector items=selection->itemList(); + std::vector items= selection->items(); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ if (SP_IS_PATH(*i)) { path = SP_PATH(*i); diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index 47927667c..9aaa0c14e 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -103,7 +103,7 @@ void MeshTool::selection_changed(Inkscape::Selection* /*sel*/) { return; } - guint n_obj = selection->itemList().size(); + guint n_obj = selection->items().size(); if (!drag->isNonEmpty() || selection->isEmpty()) { return; @@ -467,10 +467,10 @@ bool MeshTool::root_handler(GdkEvent* event) { if (over_line) { // We take the first item in selection, because with doubleclick, the first click // always resets selection to the single object under cursor - sp_mesh_context_split_near_point(this, selection->itemList()[0], this->mousepoint_doc, event->button.time); + sp_mesh_context_split_near_point(this, selection->items()[0], this->mousepoint_doc, event->button.time); } else { // Create a new gradient with default coordinates. - std::vector items=selection->itemList(); + std::vector items= selection->items(); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ SPItem *item = *i; SPGradientType new_type = SP_GRADIENT_TYPE_MESH; @@ -945,7 +945,7 @@ static void sp_mesh_end_drag(MeshTool &rc) { } else { // Starting from empty space: // Sort items so that the topmost comes last - std::vector items(selection->itemList()); + std::vector items(selection->items()); sort(items.begin(),items.end(),sp_item_repr_compare_position); // take topmost vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(items.back()), fill_or_stroke); @@ -955,7 +955,7 @@ static void sp_mesh_end_drag(MeshTool &rc) { SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-opacity", "1.0"); - std::vector items=selection->itemList(); + std::vector items= selection->items(); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ //FIXME: see above @@ -972,7 +972,7 @@ static void sp_mesh_end_drag(MeshTool &rc) { // status text; we do not track coords because this branch is run once, not all the time // during drag - int n_objects = selection->itemList().size(); + int n_objects = selection->items().size(); rc.message_context->setF(Inkscape::NORMAL_MESSAGE, ngettext("Gradient for %d object; with Ctrl to snap angle", "Gradient for %d objects; with Ctrl to snap angle", n_objects), diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 23aaf6bb1..f7a725794 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -407,7 +407,7 @@ void NodeTool::selection_changed(Inkscape::Selection *sel) { std::set shapes; - std::vector items=sel->itemList(); + std::vector items= sel->items(); for(std::vector::const_iterator i=items.begin();i!=items.end();++i){ SPObject *obj = *i; @@ -444,7 +444,7 @@ void NodeTool::selection_changed(Inkscape::Selection *sel) { } _previous_selection = _current_selection; - _current_selection = sel->itemList(); + _current_selection = sel->items(); this->_multipath->setItems(shapes); this->update_tip(NULL); diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index b5ec3d88e..676a41eaa 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -477,7 +477,7 @@ bool SelectTool::root_handler(GdkEvent* event) { case GDK_2BUTTON_PRESS: if (event->button.button == 1) { if (!selection->isEmpty()) { - SPItem *clicked_item = selection->itemList()[0]; + SPItem *clicked_item = selection->items()[0]; if (dynamic_cast(clicked_item) && !dynamic_cast(clicked_item)) { // enter group if it's not a 3D box desktop->setCurrentLayer(clicked_item); diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 9adaf3879..4f36a827f 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -210,7 +210,7 @@ void SprayTool::update_cursor(bool /*with_shift*/) { gchar *sel_message = NULL; if (!desktop->selection->isEmpty()) { - num = desktop->selection->itemList().size(); + num = desktop->selection->items().size(); sel_message = g_strdup_printf(ngettext("%i object selected","%i objects selected",num), num); } else { sel_message = g_strdup_printf("%s", _("Nothing selected")); @@ -591,7 +591,7 @@ static bool fit_item(SPDesktop *desktop, if (selection->isEmpty()) { return false; } - std::vector const items_selected(selection->itemList()); + std::vector const items_selected(selection->items()); std::vector items_down_erased; for (std::vector::const_iterator i=items_down.begin(); i!=items_down.end(); ++i) { SPItem *item_down = *i; @@ -1002,7 +1002,7 @@ static bool sp_spray_recursive(SPDesktop *desktop, SPItem *unionResult = NULL; // Previous union int i=1; - std::vector items=selection->itemList(); + std::vector items= selection->items(); for(std::vector::const_iterator it=items.begin();it!=items.end(); ++it){ SPItem *item1 = *it; if (i == 1) { @@ -1170,7 +1170,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point double move_standard_deviation = get_move_standard_deviation(tc); { - std::vector const items(selection->itemList()); + std::vector const items(selection->items()); for(std::vector::const_iterator i=items.begin();i!=items.end(); ++i){ SPItem *item = *i; @@ -1299,7 +1299,7 @@ bool SprayTool::root_handler(GdkEvent* event) { guint num = 0; if (!desktop->selection->isEmpty()) { - num = desktop->selection->itemList().size(); + num = desktop->selection->items().size(); } if (num == 0) { this->message_context->flash(Inkscape::ERROR_MESSAGE, _("Nothing selected! Select objects to spray.")); diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index 36fe26e76..6da6526bc 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -1158,7 +1158,7 @@ SPItem *sp_event_context_find_item(SPDesktop *desktop, Geom::Point const &p, if (select_under) { SPItem *selected_at_point = desktop->getItemFromListAtPointBottom( - desktop->selection->itemList(), p); + desktop->selection->items(), p); item = desktop->getItemAtPoint(p, into_groups, selected_at_point); if (item == NULL) { // we may have reached bottom, flip over to the top item = desktop->getItemAtPoint(p, into_groups, NULL); diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index 39a7a3f0b..4da8060e2 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -153,7 +153,7 @@ void TweakTool::update_cursor (bool with_shift) { gchar *sel_message = NULL; if (!desktop->selection->isEmpty()) { - num = desktop->selection->itemList().size(); + num = desktop->selection->items().size(); sel_message = g_strdup_printf(ngettext("%i object selected","%i objects selected",num), num); } else { sel_message = g_strdup_printf("%s", _("Nothing selected")); @@ -1076,7 +1076,7 @@ sp_tweak_dilate (TweakTool *tc, Geom::Point event_p, Geom::Point p, Geom::Point double move_force = get_move_force(tc); double color_force = MIN(sqrt(path_force)/20.0, 1); - std::vector items=selection->itemList(); + std::vector items= selection->items(); for(std::vector::const_iterator i=items.begin();i!=items.end(); ++i){ SPItem *item = *i; @@ -1185,7 +1185,7 @@ bool TweakTool::root_handler(GdkEvent* event) { guint num = 0; if (!desktop->selection->isEmpty()) { - num = desktop->selection->itemList().size(); + num = desktop->selection->items().size(); } if (num == 0) { this->message_context->flash(Inkscape::ERROR_MESSAGE, _("Nothing selected! Select objects to tweak.")); diff --git a/src/ui/widget/style-subject.cpp b/src/ui/widget/style-subject.cpp index 5f697e420..059d1a4e3 100644 --- a/src/ui/widget/style-subject.cpp +++ b/src/ui/widget/style-subject.cpp @@ -58,7 +58,7 @@ Inkscape::Selection *StyleSubject::Selection::_getSelection() const { std::vector StyleSubject::Selection::list() { Inkscape::Selection *selection = _getSelection(); if(selection) { - return std::vector(selection->range().begin(), selection->range().end()); + return std::vector(selection->objects().begin(), selection->objects().end()); } return std::vector(); diff --git a/src/vanishing-point.cpp b/src/vanishing-point.cpp index 32ccbad93..a6be353f8 100644 --- a/src/vanishing-point.cpp +++ b/src/vanishing-point.cpp @@ -258,7 +258,7 @@ VanishingPoint::set_pos(Proj::Pt2 const &pt) { std::list VanishingPoint::selectedBoxes(Inkscape::Selection *sel) { std::list sel_boxes; - std::vector itemlist=sel->itemList(); + std::vector itemlist= sel->items(); for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i) { SPItem *item = *i; SPBox3D *box = dynamic_cast(item); @@ -397,7 +397,7 @@ VPDragger::VPsOfSelectedBoxes() { VanishingPoint *vp; // FIXME: Should we take the selection from the parent VPDrag? I guess it shouldn't make a difference. Inkscape::Selection *sel = SP_ACTIVE_DESKTOP->getSelection(); - std::vector itemlist=sel->itemList(); + std::vector itemlist= sel->items(); for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i) { SPItem *item = *i; SPBox3D *box = dynamic_cast(item); @@ -575,7 +575,7 @@ VPDrag::updateDraggers () g_return_if_fail (this->selection != NULL); - std::vector itemlist=this->selection->itemList(); + std::vector itemlist= this->selection->items(); for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i) { SPItem *item = *i; SPBox3D *box = dynamic_cast(item); @@ -607,7 +607,7 @@ VPDrag::updateLines () g_return_if_fail (this->selection != NULL); - std::vector itemlist=this->selection->itemList(); + std::vector itemlist= this->selection->items(); for (std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i) { SPItem *item = *i; SPBox3D *box = dynamic_cast(item); @@ -625,7 +625,7 @@ VPDrag::updateBoxHandles () // FIXME: Is there a way to update the knots without accessing the // (previously) statically linked function KnotHolder::update_knots? - std::vector sel = selection->itemList(); + std::vector sel = selection->items(); if (sel.empty()) return; // no selection diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index 7b872e8b1..5db714f85 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -97,7 +97,7 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v gchar* namespaced_name = g_strconcat("sodipodi:", value_name, NULL); bool modmade = false; - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { @@ -163,7 +163,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) bool modmade = false; if ( ege_select_one_action_get_active(act) != 0 ) { - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { @@ -174,7 +174,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) } } } else { - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { @@ -264,7 +264,7 @@ static void sp_arc_toolbox_selection_changed(Inkscape::Selection *selection, GOb purge_repr_listener( tbl, tbl ); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index 733fb34e8..54b4be547 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -97,7 +97,7 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl gchar *value = is_orthog ? orthog_str : polyline_str ; bool modmade = false; - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; @@ -144,7 +144,7 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) g_ascii_dtostr(value, G_ASCII_DTOSTR_BUF_SIZE, newValue); bool modmade = false; - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; @@ -227,7 +227,7 @@ static void sp_connector_graph_layout(void) int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - graphlayout(SP_ACTIVE_DESKTOP->getSelection()->itemList()); + graphlayout(SP_ACTIVE_DESKTOP->getSelection()->items()); prefs->setInt("/options/clonecompensation/value", saved_compensation); diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index a96776894..8c3a0a0a8 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -476,7 +476,7 @@ void FillNStroke::updateFromPaint() SPDocument *document = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); - std::vector const items = selection->itemList(); + std::vector const items = selection->items(); switch (psel->mode) { case SPPaintSelector::MODE_EMPTY: diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index a44e9962e..ab345b73f 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -116,7 +116,7 @@ void gr_apply_gradient(Inkscape::Selection *selection, GrDrag *drag, SPGradient } // If no drag or no dragger selected, act on selection - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ gr_apply_gradient_to_item(*i, gr, initialType, initialMode, initialMode); } @@ -216,7 +216,7 @@ void gr_get_dt_selected_gradient(Inkscape::Selection *selection, SPGradient *&gr { SPGradient *gradient = 0; - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i;// get the items gradient, not the getVector() version SPStyle *style = item->style; @@ -284,7 +284,7 @@ void gr_read_selection( Inkscape::Selection *selection, } // If no selected dragger, read desktop selection - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; SPStyle *style = item->style; diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index 3643ce00c..5d326253c 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -89,7 +89,7 @@ void ms_read_selection( Inkscape::Selection *selection, bool first = true; ms_type = SP_MESH_TYPE_COONS; - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; SPStyle *style = item->style; @@ -216,7 +216,7 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMesh *&ms_sel { SPMesh *gradient = 0; - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i;// get the items gradient, not the getVector() version SPStyle *style = item->style; diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index 55127206c..34cebbe1b 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -240,7 +240,7 @@ static void sp_pencil_tb_defaults(GtkWidget * /*widget*/, GObject *obj) static void sp_simplify_flatten(GtkWidget * /*widget*/, GObject *obj) { SPDesktop *desktop = static_cast(g_object_get_data(obj, "desktop")); - std::vector selected = desktop->getSelection()->itemList(); + std::vector selected = desktop->getSelection()->items(); for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it){ SPLPEItem* lpeitem = dynamic_cast(*it); if (lpeitem && lpeitem->hasPathEffect()){ @@ -285,7 +285,7 @@ static void sp_pencil_tb_tolerance_value_changed(GtkAdjustment *adj, GObject *tb gtk_adjustment_get_value(adj)); g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); SPDesktop *desktop = static_cast(g_object_get_data(tbl, "desktop")); - std::vector selected = desktop->getSelection()->itemList(); + std::vector selected = desktop->getSelection()->items(); for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it){ SPLPEItem* lpeitem = dynamic_cast(*it); if (lpeitem && lpeitem->hasPathEffect()){ diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index bc27d003c..2ee38608b 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -106,7 +106,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ if (SP_IS_RECT(*i)) { if (gtk_adjustment_get_value(adj) != 0) { @@ -243,7 +243,7 @@ static void sp_rect_toolbox_selection_changed(Inkscape::Selection *selection, GO } purge_repr_listener( tbl, tbl ); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ if (SP_IS_RECT(*i)) { n_selected++; diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index 7e7398091..8f5f10bf8 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -79,7 +79,7 @@ static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustr gchar* namespaced_name = g_strconcat("sodipodi:", value_name.data(), NULL); bool modmade = false; - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ SPItem *item = *i; if (SP_IS_SPIRAL(item)) { @@ -195,7 +195,7 @@ static void sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, purge_repr_listener( tbl, tbl ); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ SPItem *item = *i; if (SP_IS_SPIRAL(item)) { diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index 982a3c854..fc8757162 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -83,7 +83,7 @@ static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKlu bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { @@ -128,7 +128,7 @@ static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { @@ -185,7 +185,7 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d gtk_action_set_visible( prop_action, !flat ); } - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { @@ -224,7 +224,7 @@ static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludg bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { @@ -264,7 +264,7 @@ static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { @@ -367,7 +367,7 @@ sp_star_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) purge_repr_listener( tbl, tbl ); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 84a6e77ad..7ed2c3180 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -515,7 +515,7 @@ void StrokeStyle::markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, //spw->updateMarkerHist(which); Inkscape::Selection *selection = spw->desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (!SP_IS_SHAPE(item) || SP_IS_RECT(item)) { // can't set marker to rect, until it's converted to using @@ -988,7 +988,7 @@ StrokeStyle::updateLine() if (!sel || sel->isEmpty()) return; - std::vector const objects = sel->itemList(); + std::vector const objects = sel->items(); SPObject * const object = objects[0]; SPStyle * const style = object->style; @@ -1044,7 +1044,7 @@ StrokeStyle::scaleLine() SPDocument *document = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); - std::vector items=selection->itemList(); + std::vector items= selection->items(); /* TODO: Create some standardized method */ SPCSSAttr *css = sp_repr_css_attr_new(); diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 23acb74af..3d08b04f1 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -378,7 +378,7 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) // move the x of all texts to preserve the same bbox Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ if (SP_IS_TEXT(*i)) { SPItem *item = *i; @@ -560,7 +560,7 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) // Only need to save for undo if a text item has been changed. Inkscape::Selection *selection = desktop->getSelection(); bool modmade = false; - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ if (SP_IS_TEXT (*i)) { modmade = true; @@ -625,7 +625,7 @@ static void sp_text_lineheight_unit_changed( gpointer /* */, GObject *tbl ) SPDesktop *desktop = SP_ACTIVE_DESKTOP; Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); // Convert between units if ((unit->abbr == "" || unit->abbr == "em") && old_unit == SP_CSS_UNIT_EX) { @@ -1120,7 +1120,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Only flowed text can be justified, only normal text can be kerned... // Find out if we have flowed text now so we can use it several places gboolean isFlow = false; - std::vector itemlist=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + std::vector itemlist= SP_ACTIVE_DESKTOP->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ // const gchar* id = reinterpret_cast(items->data)->getId(); // std::cout << " " << id << std::endl; -- cgit v1.2.3 From 47a71e1eb00db2a3b6030ff545f624283a95e174 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sun, 26 Jun 2016 09:24:02 +0530 Subject: Add/Remove objects to/from selector (bzr r14949.1.27) --- src/ui/dialog/styledialog.cpp | 252 ++++++++++++++++++++++++++++-------------- src/ui/dialog/styledialog.h | 11 +- 2 files changed, 178 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index a7a803edd..6cb970eae 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -59,13 +59,20 @@ StyleDialog::StyleDialog() : _scrolledWindow.add(_treeView); _scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); - _store = Gtk::ListStore::create(_mColumns); + _store = Gtk::TreeStore::create(_mColumns); _treeView.set_model(_store); Inkscape::UI::Widget::AddToIcon * addRenderer = manage( new Inkscape::UI::Widget::AddToIcon() ); addRenderer->property_active() = true; - _treeView.append_column("type", *addRenderer); + + int addCol = _treeView.append_column("type", *addRenderer) - 1; + + Gtk::TreeViewColumn *col = _treeView.get_column(addCol); + if ( col ) { + col->add_attribute( addRenderer->property_active(), _mColumns._colAddRemove ); + } + _treeView.append_column("Selector Name", _mColumns._selectorLabel); create = manage( new Gtk::Button() ); @@ -99,6 +106,11 @@ StyleDialog::StyleDialog() : _document = _targetDesktop->doc(); _num = _document->getReprRoot()->childCount(); _sValue = _populateTree(_getSelectorVec()); + + _treeView.signal_button_press_event().connect(sigc::mem_fun(*this, + &StyleDialog:: + _handleButtonEvent), + false); } StyleDialog::~StyleDialog() @@ -119,7 +131,7 @@ void StyleDialog::setDesktop( SPDesktop* desktop ) */ void StyleDialog::_addSelector() { - Gtk::TreeModel::Row row = *(_store->append()); + _row = *(_store->append()); /** * On clicking '+' button, an entrybox with default text opens up. If an @@ -154,22 +166,22 @@ void StyleDialog::_addSelector() * selector. If text like 'red' is written in entrybox, it is prefixed * with a dot. */ - std::string selectorName = ""; if ( !textEditPtr->get_text().empty() ) { if ( textEditPtr->get_text().at(0) == '#' || textEditPtr->get_text().at(0) == '.' ) - selectorName = textEditPtr->get_text(); + _selectorName = textEditPtr->get_text(); else - selectorName = "." + textEditPtr->get_text(); + _selectorName = "." + textEditPtr->get_text(); } else { - selectorName = ".Class1"; + _selectorName = ".Class1"; } switch (result) { case Gtk::RESPONSE_OK: textDialogPtr->hide(); - row[_mColumns._selectorLabel] = selectorName; + _row[_mColumns._selectorLabel] = _selectorName; + _row[_mColumns._colAddRemove] = true; break; default: break; @@ -185,11 +197,11 @@ void StyleDialog::_addSelector() * created with an empty value. Also if a class selector is added, then * class attribute for the selected object is set too. */ - if ( _desktop->selection ) { + SPObject *obj; + if ( !_desktop->getSelection()->list().empty() ) { std::vector selected = _desktop->getSelection()->list(); - std::string selectorValue; for ( unsigned i = 0; i < selected.size(); ++i ) { - SPObject *obj = selected.at(i); + obj = selected.at(i); std::string style; if (obj->getRepr()->attribute("style")) @@ -201,7 +213,7 @@ void StyleDialog::_addSelector() if ( std::string(property) == "style" ) { - selectorValue = row[_mColumns._selectorLabel] + "{" + _selectorValue = _row[_mColumns._selectorLabel] + "{" + std::string(value) + "}" + "\n"; } } @@ -213,7 +225,7 @@ void StyleDialog::_addSelector() obj->getRepr()->setAttribute("style", style); } - if ( strcmp(selectorName.substr(0,1).c_str(), ".") == 0 ){ + if ( strcmp(_selectorName.substr(0,1).c_str(), ".") == 0 ){ if (!obj->getRepr()->attribute("class")) obj->getRepr()->setAttribute("class", textEditPtr->get_text() .erase(0,1)); @@ -224,49 +236,49 @@ void StyleDialog::_addSelector() + " " + textEditPtr->get_text() .erase(0,0)); } + } + } + else { + _selectorValue = _selectorName + "{" + "}" + "\n"; + } - /** - * @brief root - * A new style element is added to the document with value obtained - * from selectorValue above. If style element already exists, then - * the new selector's content is appended to its previous content. - */ - for ( unsigned i = 0; i < _num; ++i ) - { - if ( std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style" ) - { - _styleExists = true; - _styleChild = _document->getReprRoot()->nthChild(i); - break; - } - else - _styleExists = false; - } - - if ( _styleExists ) - { - _sValue = _sValue + selectorValue; - _styleChild->firstChild()->setContent(_sValue.c_str()); - } - else - { - _sValue = selectorValue; - Inkscape::XML::Node *root = obj->getRepr()->document()->root(); - Inkscape::XML::Node *newChild = obj->getRepr()->document() - ->createElement("svg:style"); - Inkscape::XML::Node *smallChildren = obj->getRepr()->document() - ->createTextNode(selectorValue.c_str()); - - newChild->appendChild(smallChildren); - Inkscape::GC::release(smallChildren); - - root->addChild(newChild, NULL); - Inkscape::GC::release(newChild); - } - _selectorVec.push_back(std::make_pair(selectorName, selectorValue)); + /** + * @brief root + * A new style element is added to the document with value obtained + * from selectorValue above. If style element already exists, then + * the new selector's content is appended to its previous content. + */ + for ( unsigned i = 0; i < _num; ++i ) { + if ( std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style" ) { + _styleExists = true; + _styleChild = _document->getReprRoot()->nthChild(i); + break; } + else { + _styleExists = false; + } + } + + if ( _styleExists ) { + _sValue = _sValue + _selectorValue; + _styleChild->firstChild()->setContent(_sValue.c_str()); + } + else { + _sValue = _selectorValue; + Inkscape::XML::Node *root = _document->getReprDoc()->root(); + Inkscape::XML::Node *newChild = _document->getReprDoc() + ->createElement("svg:style"); + Inkscape::XML::Node *smallChildren = _document->getReprDoc() + ->createTextNode(_selectorValue.c_str()); + + newChild->appendChild(smallChildren); + Inkscape::GC::release(smallChildren); + + root->addChild(newChild, NULL); + Inkscape::GC::release(newChild); } + _selectorVec.push_back(std::make_pair(_selectorName, _selectorValue)); } /** @@ -283,26 +295,19 @@ void StyleDialog::_delSelector() std::vector >selVec = _getSelectorVec(); Gtk::TreeModel::Path path; - if (iter) - { + if (iter) { Gtk::TreeModel::Row row = *iter; path = _treeView.get_model()->get_path(iter); int i = atoi(path.to_string().c_str()); - if (selVec.size() != 0) - { + if ( selVec.size() != 0 ) { selVec.erase(selVec.begin()+i); _sValue.clear(); - if (selVec.size() != 0) - { - for (unsigned i = 0; i < selVec.size(); ++i) - { - std::string selValue = (selVec[i].first + "{" - + selVec[i].second + " }\n"); - _sValue.append(selValue.c_str()); - } - + for ( unsigned i = 0; i < selVec.size(); ++i ) { + std::string selValue = (selVec[i].first + "{" + + selVec[i].second + " }\n"); + _sValue.append(selValue.c_str()); } /** @@ -311,17 +316,13 @@ void StyleDialog::_delSelector() * element is updated else the _styleChild is set and its content * is set to an empty string. */ - if (!_sValue.empty() && _styleChild) + if ( !_sValue.empty() && _styleChild ) _styleChild->firstChild()->setContent(_sValue.c_str()); - else - { - for ( unsigned i = 0; i < _num; ++i ) - { + else { + for ( unsigned i = 0; i < _num; ++i ) { if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) - { _styleChild = _document->getReprRoot()->nthChild(i); - } } _styleChild->firstChild()->setContent(""); } @@ -358,20 +359,26 @@ std::vector >StyleDialog::_getSelectorVec() std::string key, value; std::vector > selVec; - for ( unsigned i = 0; i < _num; ++i ) - { + for ( unsigned i = 0; i < _num; ++i ) { if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) { std::stringstream str; str << _document->getReprRoot()->nthChild(i)->firstChild()->content(); std::string sel; - while(std::getline(str, sel, '\n')){ + /** + * If a selector without any style attribute content is added, the + * value is set to empty so that its corresponding XML repr is added. + */ + while( std::getline(str, sel, '\n') ){ REMOVE_SPACES(sel); - if (!sel.empty()) + if ( !sel.empty() ) { key = strtok(strdup(sel.c_str()), "{"); - value = strtok(NULL, "}"); + if ( strtok(NULL, "}") != NULL ) + value = strtok(NULL, "}"); + else + value = ""; selVec.push_back(std::make_pair(key, value)); } } @@ -404,18 +411,99 @@ std::string StyleDialog::_populateTree(std::vector 0) del->set_sensitive(true); - for ( unsigned i = 0; i < _num; ++i ) - { + for ( unsigned i = 0; i < _num; ++i ) { if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) - { _styleChild = _document->getReprRoot()->nthChild(i); - } } return selectorValue; } +/** + * @brief StyleDialog::_handleButtonEvent + * @param event + * @return + * This function handles the event when '+' button in front of a selector name + * is clicked. The selected objects (if any) is added to the selector as a child + * in the treeview. + * TODO: Appending children in XML repr. + */ + +bool StyleDialog::_handleButtonEvent(GdkEventButton *event) +{ + if ( event->type == GDK_BUTTON_PRESS && event->button == 1 ) + { + Gtk::TreeViewColumn *col = 0; + + Gtk::TreeModel::Path path; + int x = static_cast(event->x); + int y = static_cast(event->y); + int x2 = 0; + int y2 = 0; + if ( _treeView.get_path_at_pos( x, y, path, col, x2, y2 ) ) { + if ( col == _treeView.get_column(0) ) + { + if ( _desktop->selection ) + { + std::vectorsel = _desktop->selection->list(); + for (unsigned i = 0; i < sel.size(); ++i) + { + SPObject *obj = sel[i]; + Glib::RefPtr refTreeSelection = + _treeView.get_selection(); + Gtk::TreeModel::iterator iter = refTreeSelection-> + get_selected(); + + if ( iter ) + { + Gtk::TreeModel::Row row = *iter; +// SPObject *object = row[_mColumns._colObj]; + + typedef Gtk::TreeModel::Children type_children; + type_children children = row->children(); + Gtk::TreeModel::Row childrow; + + if ( children.size() == 0 && row->parent() == 0 ) + { + childrow = *(_store->append(row->children())); + childrow[_mColumns._selectorLabel] = obj->getId(); + childrow[_mColumns._colAddRemove] = false; +// childrow[_mColumns._colObj] = obj; +// object->getRepr()->appendChild(obj->getRepr()); + } + else + { + for( type_children::iterator it = children.begin(); + it != children.end(); ++it ) + { + Gtk::TreeModel::iterator i = it; + path = _treeView.get_model()->get_path(i); + + if( (*it)->get_value(_mColumns._selectorLabel) + != obj->getId() ) + { + childrow = *(_store->append(row.children())); + childrow[_mColumns._selectorLabel] = obj->getId(); + childrow[_mColumns._colAddRemove] = false; +// childrow[_mColumns._colObj] = obj; +// object->getRepr()->appendChild(obj->getRepr()); + + } + else { + std::cout << "Do nothing" << std::endl; + } + } + } +// std::cout << "repr" << object->getRepr()->content(); + } + } + } + } + } + } +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 502a7a3d4..ff4de9a97 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include #include @@ -46,13 +46,15 @@ private: std::vector >_selectorVec; std::vector > _getSelectorVec(); std::string _populateTree(std::vector >); + bool _handleButtonEvent(GdkEventButton *event); class ModelColumns : public Gtk::TreeModel::ColumnRecord { public: ModelColumns() - { add(_selectorLabel); } + { add(_selectorLabel); add(_colAddRemove); } Gtk::TreeModelColumn _selectorLabel; + Gtk::TreeModelColumn _colAddRemove; }; SPDesktop* _desktop; @@ -61,7 +63,7 @@ private: Gtk::VBox _mainBox; Gtk::HBox _buttonBox; Gtk::TreeView _treeView; - Glib::RefPtr _store; + Glib::RefPtr _store; Gtk::ScrolledWindow _scrolledWindow; Gtk::Button* del; Gtk::Button* create; @@ -70,6 +72,9 @@ private: std::string _sValue ; Inkscape::XML::Node *_styleChild; unsigned _num; + std::string _selectorName = ""; + std::string _selectorValue; + Gtk::TreeModel::Row _row; // Signal handlers void _addSelector(); -- cgit v1.2.3 From a401c22ec8acb2a94701ea0fbb7ecf08683ebca1 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sun, 26 Jun 2016 11:33:48 +0530 Subject: Fix a crash when deleting selectors and some coding style corrections (bzr r14949.1.29) --- src/ui/dialog/styledialog.cpp | 134 +++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 75 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 6cb970eae..3c1ed0a5d 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -148,8 +148,9 @@ void StyleDialog::_addSelector() * is(are) selected and user clicks '+' at the bottom of dialog, the * entrybox will have the id(s) of the selected objects as text. */ - if ( _desktop->selection->isEmpty() ) + if (_desktop->selection->isEmpty()) { textEditPtr->set_text("Class1"); + } else { std::vector selected = _desktop->getSelection()->list(); textEditPtr->set_text(_setClassAttribute(selected)); @@ -166,12 +167,14 @@ void StyleDialog::_addSelector() * selector. If text like 'red' is written in entrybox, it is prefixed * with a dot. */ - if ( !textEditPtr->get_text().empty() ) { - if ( textEditPtr->get_text().at(0) == '#' || - textEditPtr->get_text().at(0) == '.' ) + if (!textEditPtr->get_text().empty()) { + if (textEditPtr->get_text().at(0) == '#' || + textEditPtr->get_text().at(0) == '.') { _selectorName = textEditPtr->get_text(); - else + } + else { _selectorName = "." + textEditPtr->get_text(); + } } else { _selectorName = ".Class1"; @@ -198,43 +201,41 @@ void StyleDialog::_addSelector() * class attribute for the selected object is set too. */ SPObject *obj; - if ( !_desktop->getSelection()->list().empty() ) { + if (!_desktop->getSelection()->list().empty()) { std::vector selected = _desktop->getSelection()->list(); - for ( unsigned i = 0; i < selected.size(); ++i ) { + for (unsigned i = 0; i < selected.size(); ++i) { obj = selected.at(i); std::string style; - if (obj->getRepr()->attribute("style")) - { - for ( List iter = obj->getRepr()->attributeList(); - iter; ++iter ) { + if (obj->getRepr()->attribute("style")) { + for (List iter = obj->getRepr()->attributeList(); + iter; ++iter) { gchar const * property = g_quark_to_string(iter->key); gchar const * value = iter->value; - if ( std::string(property) == "style" ) - { + if (std::string(property) == "style") { _selectorValue = _row[_mColumns._selectorLabel] + "{" + std::string(value) + "}" + "\n"; } } } - - else - { + else { style = " "; obj->getRepr()->setAttribute("style", style); } - if ( strcmp(_selectorName.substr(0,1).c_str(), ".") == 0 ){ - if (!obj->getRepr()->attribute("class")) + if (strcmp(_selectorName.substr(0,1).c_str(), ".") == 0) { + if (!obj->getRepr()->attribute("class")) { obj->getRepr()->setAttribute("class", textEditPtr->get_text() .erase(0,1)); - else + } + else { obj->getRepr()->setAttribute("class", std::string(obj-> getRepr()-> attribute("class")) + " " + textEditPtr->get_text() .erase(0,0)); + } } } } @@ -248,9 +249,9 @@ void StyleDialog::_addSelector() * from selectorValue above. If style element already exists, then * the new selector's content is appended to its previous content. */ - for ( unsigned i = 0; i < _num; ++i ) { - if ( std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style" ) { + for (unsigned i = 0; i < _num; ++i) { + if (std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style") { _styleExists = true; _styleChild = _document->getReprRoot()->nthChild(i); break; @@ -260,7 +261,7 @@ void StyleDialog::_addSelector() } } - if ( _styleExists ) { + if (_styleExists) { _sValue = _sValue + _selectorValue; _styleChild->firstChild()->setContent(_sValue.c_str()); } @@ -300,11 +301,11 @@ void StyleDialog::_delSelector() path = _treeView.get_model()->get_path(iter); int i = atoi(path.to_string().c_str()); - if ( selVec.size() != 0 ) { + if (selVec.size() != 0) { selVec.erase(selVec.begin()+i); _sValue.clear(); - for ( unsigned i = 0; i < selVec.size(); ++i ) { + for (unsigned i = 0; i < selVec.size(); ++i) { std::string selValue = (selVec[i].first + "{" + selVec[i].second + " }\n"); _sValue.append(selValue.c_str()); @@ -316,13 +317,15 @@ void StyleDialog::_delSelector() * element is updated else the _styleChild is set and its content * is set to an empty string. */ - if ( !_sValue.empty() && _styleChild ) + if (!_sValue.empty() && _styleChild) { _styleChild->firstChild()->setContent(_sValue.c_str()); + } else { - for ( unsigned i = 0; i < _num; ++i ) { - if ( std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style" ) + for (unsigned i = 0; i < _num; ++i) { + if (std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style") { _styleChild = _document->getReprRoot()->nthChild(i); + } } _styleChild->firstChild()->setContent(""); } @@ -359,9 +362,8 @@ std::vector >StyleDialog::_getSelectorVec() std::string key, value; std::vector > selVec; - for ( unsigned i = 0; i < _num; ++i ) { - if ( std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style" ) - { + for (unsigned i = 0; i < _num; ++i) { + if (std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style") { std::stringstream str; str << _document->getReprRoot()->nthChild(i)->firstChild()->content(); std::string sel; @@ -370,21 +372,19 @@ std::vector >StyleDialog::_getSelectorVec() * If a selector without any style attribute content is added, the * value is set to empty so that its corresponding XML repr is added. */ - while( std::getline(str, sel, '\n') ){ + while(std::getline(str, sel, '\n')) { REMOVE_SPACES(sel); - if ( !sel.empty() ) - { + if (!sel.empty()) { key = strtok(strdup(sel.c_str()), "{"); - if ( strtok(NULL, "}") != NULL ) - value = strtok(NULL, "}"); - else - value = ""; + char *temp = strtok(NULL, "}"); + if (strtok(temp, "}") != NULL) { + value = strtok(temp, "}"); + } selVec.push_back(std::make_pair(key, value)); } } } } - return selVec; } @@ -400,7 +400,7 @@ std::string StyleDialog::_populateTree(std::vector > _selectVec = _selVec; std::string selectorValue; - for( unsigned it = 0; it < _selectVec.size(); ++it ) { + for(unsigned it = 0; it < _selectVec.size(); ++it) { Gtk::TreeModel::Row row = *(_store->append()); row[_mColumns._selectorLabel] = _selectVec[it].first; std::string selValue = _selectVec[it].first + " { " @@ -408,13 +408,15 @@ std::string StyleDialog::_populateTree(std::vector 0) + if (_selectVec.size() > 0) { del->set_sensitive(true); + } - for ( unsigned i = 0; i < _num; ++i ) { - if ( std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style" ) + for (unsigned i = 0; i < _num; ++i) { + if (std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style") { _styleChild = _document->getReprRoot()->nthChild(i); + } } return selectorValue; @@ -432,70 +434,52 @@ std::string StyleDialog::_populateTree(std::vectortype == GDK_BUTTON_PRESS && event->button == 1 ) - { + if (event->type == GDK_BUTTON_PRESS && event->button == 1) { Gtk::TreeViewColumn *col = 0; - Gtk::TreeModel::Path path; int x = static_cast(event->x); int y = static_cast(event->y); int x2 = 0; int y2 = 0; - if ( _treeView.get_path_at_pos( x, y, path, col, x2, y2 ) ) { - if ( col == _treeView.get_column(0) ) - { - if ( _desktop->selection ) - { + if (_treeView.get_path_at_pos(x, y, path, col, x2, y2)) { + if (col == _treeView.get_column(0)) { + if (_desktop->selection) { std::vectorsel = _desktop->selection->list(); - for (unsigned i = 0; i < sel.size(); ++i) - { + for (unsigned i = 0; i < sel.size(); ++i) { SPObject *obj = sel[i]; Glib::RefPtr refTreeSelection = _treeView.get_selection(); Gtk::TreeModel::iterator iter = refTreeSelection-> get_selected(); - if ( iter ) - { + if (iter) { Gtk::TreeModel::Row row = *iter; -// SPObject *object = row[_mColumns._colObj]; - typedef Gtk::TreeModel::Children type_children; type_children children = row->children(); Gtk::TreeModel::Row childrow; - if ( children.size() == 0 && row->parent() == 0 ) - { + if (children.size() == 0 && row->parent() == 0) { childrow = *(_store->append(row->children())); childrow[_mColumns._selectorLabel] = obj->getId(); childrow[_mColumns._colAddRemove] = false; -// childrow[_mColumns._colObj] = obj; -// object->getRepr()->appendChild(obj->getRepr()); } - else - { - for( type_children::iterator it = children.begin(); - it != children.end(); ++it ) - { + else { + for(type_children::iterator it = children.begin(); + it != children.end(); ++it) { Gtk::TreeModel::iterator i = it; path = _treeView.get_model()->get_path(i); - if( (*it)->get_value(_mColumns._selectorLabel) - != obj->getId() ) - { + if((*it)->get_value(_mColumns._selectorLabel) + != obj->getId()) { childrow = *(_store->append(row.children())); childrow[_mColumns._selectorLabel] = obj->getId(); childrow[_mColumns._colAddRemove] = false; -// childrow[_mColumns._colObj] = obj; -// object->getRepr()->appendChild(obj->getRepr()); - } else { std::cout << "Do nothing" << std::endl; } } } -// std::cout << "repr" << object->getRepr()->content(); } } } -- cgit v1.2.3 From 4a85a11d89d34739eb43496047ee7af67d635c1c Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sun, 26 Jun 2016 18:52:52 +0530 Subject: Select objects corresponding to selector selected in treeview (bzr r14949.1.30) --- src/ui/dialog/styledialog.cpp | 79 ++++++++++++++++++++++++++++++++++++------- src/ui/dialog/styledialog.h | 6 +++- 2 files changed, 72 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 3c1ed0a5d..1dba1d2df 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -111,6 +111,10 @@ StyleDialog::StyleDialog() : &StyleDialog:: _handleButtonEvent), false); + + _treeView.signal_row_activated().connect(sigc::mem_fun(*this, + &StyleDialog:: + _selectedRowCallback)); } StyleDialog::~StyleDialog() @@ -180,16 +184,6 @@ void StyleDialog::_addSelector() _selectorName = ".Class1"; } - switch (result) { - case Gtk::RESPONSE_OK: - textDialogPtr->hide(); - _row[_mColumns._selectorLabel] = _selectorName; - _row[_mColumns._colAddRemove] = true; - break; - default: - break; - } - del->set_sensitive(true); /** @@ -201,10 +195,12 @@ void StyleDialog::_addSelector() * class attribute for the selected object is set too. */ SPObject *obj; + bool objExists = false; if (!_desktop->getSelection()->list().empty()) { std::vector selected = _desktop->getSelection()->list(); for (unsigned i = 0; i < selected.size(); ++i) { obj = selected.at(i); + objExists = true; std::string style; if (obj->getRepr()->attribute("style")) { @@ -214,7 +210,7 @@ void StyleDialog::_addSelector() gchar const * value = iter->value; if (std::string(property) == "style") { - _selectorValue = _row[_mColumns._selectorLabel] + "{" + _selectorValue = _selectorName + "{" + std::string(value) + "}" + "\n"; } } @@ -241,9 +237,22 @@ void StyleDialog::_addSelector() } else { _selectorValue = _selectorName + "{" + "}" + "\n"; + objExists = false; } - /** + switch (result) { + case Gtk::RESPONSE_OK: + textDialogPtr->hide(); + _row[_mColumns._selectorLabel] = _selectorName; + _row[_mColumns._colAddRemove] = true; + if (objExists) { + _row[_mColumns._colObj] = obj; + } + break; + default: + break; + } + /** * @brief root * A new style element is added to the document with value obtained * from selectorValue above. If style element already exists, then @@ -462,6 +471,7 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) childrow = *(_store->append(row->children())); childrow[_mColumns._selectorLabel] = obj->getId(); childrow[_mColumns._colAddRemove] = false; + childrow[_mColumns._colObj] = obj; } else { for(type_children::iterator it = children.begin(); @@ -474,6 +484,7 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) childrow = *(_store->append(row.children())); childrow[_mColumns._selectorLabel] = obj->getId(); childrow[_mColumns._colAddRemove] = false; + childrow[_mColumns._colObj] = obj; } else { std::cout << "Do nothing" << std::endl; @@ -488,6 +499,50 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) } } +/** + * @brief StyleDialog::_selected_row_callback + * @param path + * This function selects objects in the drawing corresponding to the selector + * selected in the treeview. + */ +void StyleDialog::_selectedRowCallback(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* /* column */) +{ + _desktop->selection->clear(); + Gtk::TreeModel::iterator iter = _store->get_iter(path); + if (iter) { + Gtk::TreeModel::Row row = *iter; + Gtk::TreeModel::Children children = row.children(); + + if (row[_mColumns._colObj]) { + SPObject *obj = row[_mColumns._colObj]; + _desktop->selection->add(obj); + } + + if (children) { + _checkAllChildren(children); + } + } +} + +/** + * @brief StyleDialog::_checkAllChildren + * @param children + * This function iterates children of the row selected in treeview and selects + * the objects corresponding to any selector in child rows. + */ +void StyleDialog::_checkAllChildren(Gtk::TreeModel::Children& children) +{ + for (Gtk::TreeModel::Children::iterator iter = children.begin(); + iter!= children.end(); ++iter) { + Gtk::TreeModel::Row childrow = *iter; + if (childrow[_mColumns._colObj]) { + SPObject *obj = childrow[_mColumns._colObj]; + _desktop->selection->add(obj); + } + } +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index ff4de9a97..79897a5b6 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -47,14 +47,18 @@ private: std::vector > _getSelectorVec(); std::string _populateTree(std::vector >); bool _handleButtonEvent(GdkEventButton *event); + void _selectedRowCallback(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* /* column */); + void _checkAllChildren(Gtk::TreeModel::Children& children); class ModelColumns : public Gtk::TreeModel::ColumnRecord { public: ModelColumns() - { add(_selectorLabel); add(_colAddRemove); } + { add(_selectorLabel); add(_colAddRemove); add(_colObj); } Gtk::TreeModelColumn _selectorLabel; Gtk::TreeModelColumn _colAddRemove; + Gtk::TreeModelColumn _colObj; }; SPDesktop* _desktop; -- cgit v1.2.3 From a51df2ab1eb079b2588ccb9398440f403d11c34d Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Mon, 27 Jun 2016 16:59:48 +0200 Subject: Added more tests (bzr r14954.1.11) --- src/object-set.cpp | 28 +--------------------------- src/object-set.h | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/object-set.cpp b/src/object-set.cpp index 627544a21..518ce15a3 100644 --- a/src/object-set.cpp +++ b/src/object-set.cpp @@ -174,13 +174,8 @@ bool ObjectSet::isEmpty() { return container.size() == 0; } - SPObject *ObjectSet::single() { - if (container.size() == 1) { - return *container.begin(); - } - - return nullptr; + return container.size() == 1 ? *container.begin() : nullptr; } SPItem *ObjectSet::singleItem() { @@ -257,27 +252,6 @@ void ObjectSet::set(SPObject *object) { // _emitSignals(); } -void ObjectSet::setList(const std::vector &objs) { - _clear(); - addList(objs); -} - -void ObjectSet::addList(const std::vector &objs) { - for (std::vector::const_iterator iter = objs.begin(); iter != objs.end(); ++iter) { - SPObject *obj = *iter; - if (!includes(obj)) { - add(obj); - } - } -} - -void ObjectSet::add(const std::vector::iterator& from, const std::vector::iterator& to) { - for(auto it = from; it != to; ++it) { - _add(*it); - } -} - - Geom::OptRect ObjectSet::bounds(SPItem::BBoxType type) const { return (type == SPItem::GEOMETRIC_BBOX) ? diff --git a/src/object-set.h b/src/object-set.h index 49a875562..29083863b 100644 --- a/src/object-set.h +++ b/src/object-set.h @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include "sp-object.h" #include "sp-item.h" @@ -84,7 +86,12 @@ public: * \param from the begin iterator * \param to the end iterator */ - void add(const std::vector::iterator& from, const std::vector::iterator& to); + template + void add(InputIterator from, InputIterator to) { + for(auto it = from; it != to; ++it) { + _add(*it); + } + } /** * Removes an item from the set of selected objects. @@ -176,14 +183,27 @@ public: * * @param objs the objects to select */ - void setList(const std::vector &objs); + template + typename boost::enable_if, void>::type + setList(const std::vector &objs) { + _clear(); + addList(objs); + } /** * Adds the specified objects to selection, without deselecting first. * * @param objs the objects to select */ - void addList(std::vector const &objs); + template + typename boost::enable_if, void>::type + addList(const std::vector &objs) { + for (auto obj: objs) { + if (!includes(obj)) { + add(obj); + } + } + } /** Returns the bounding rectangle of the selection. */ Geom::OptRect bounds(SPItem::BBoxType type) const; -- cgit v1.2.3 From 94e53ff6ca6d0a595415b6f930a4a05adaeb68be Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Tue, 28 Jun 2016 22:18:31 +0530 Subject: Update XML repr when objects are added to selector & some code cleanup (bzr r14949.1.31) --- src/ui/dialog/styledialog.cpp | 180 +++++++++++++++++++++--------------------- src/ui/dialog/styledialog.h | 2 + 2 files changed, 91 insertions(+), 91 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 1dba1d2df..1b93fb550 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -172,13 +172,7 @@ void StyleDialog::_addSelector() * with a dot. */ if (!textEditPtr->get_text().empty()) { - if (textEditPtr->get_text().at(0) == '#' || - textEditPtr->get_text().at(0) == '.') { _selectorName = textEditPtr->get_text(); - } - else { - _selectorName = "." + textEditPtr->get_text(); - } } else { _selectorName = ".Class1"; @@ -252,27 +246,24 @@ void StyleDialog::_addSelector() default: break; } - /** - * @brief root + + /** * A new style element is added to the document with value obtained * from selectorValue above. If style element already exists, then * the new selector's content is appended to its previous content. */ - for (unsigned i = 0; i < _num; ++i) { - if (std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style") { - _styleExists = true; - _styleChild = _document->getReprRoot()->nthChild(i); - break; - } - else { - _styleExists = false; - } + _selectorVec.push_back(std::make_pair(_selectorName, _selectorValue)); + + if (_styleElementNode()) { + _styleChild = _styleElementNode(); + _styleExists = true; + } + else { + _styleExists = false; } if (_styleExists) { - _sValue = _sValue + _selectorValue; - _styleChild->firstChild()->setContent(_sValue.c_str()); + _updateStyleContent(); } else { _sValue = _selectorValue; @@ -288,7 +279,20 @@ void StyleDialog::_addSelector() root->addChild(newChild, NULL); Inkscape::GC::release(newChild); } - _selectorVec.push_back(std::make_pair(_selectorName, _selectorValue)); +} + +/** + * @brief StyleDialog::_updateStyleContent + * This function updates the content in style element as new selectors (or + * objects) are added/removed. + */ +void StyleDialog::_updateStyleContent() +{ + std::string styleContent = ""; + for (unsigned i = 0; i < _selectorVec.size(); ++i) { + styleContent = styleContent + _selectorVec[i].second; + } + _styleElementNode()->firstChild()->setContent(styleContent.c_str()); } /** @@ -297,12 +301,13 @@ void StyleDialog::_addSelector() * of selected row is obtained and the corresponding selector and its values are * deleted from the selector vector. Then _sValue's content is reset and contains * only selectors remaining in the selVec (or treeview). + * TODO: get index of children of rows for correct deletion of rows having + * children. */ void StyleDialog::_delSelector() { Glib::RefPtr refTreeSelection = _treeView.get_selection(); Gtk::TreeModel::iterator iter = refTreeSelection->get_selected(); - std::vector >selVec = _getSelectorVec(); Gtk::TreeModel::Path path; if (iter) { @@ -310,39 +315,46 @@ void StyleDialog::_delSelector() path = _treeView.get_model()->get_path(iter); int i = atoi(path.to_string().c_str()); - if (selVec.size() != 0) { - selVec.erase(selVec.begin()+i); - _sValue.clear(); - - for (unsigned i = 0; i < selVec.size(); ++i) { - std::string selValue = (selVec[i].first + "{" - + selVec[i].second + " }\n"); - _sValue.append(selValue.c_str()); - } + if (_selectorVec.size() != 0) { + _selectorVec.erase(_selectorVec.begin()+i); /** - * Only if a value exists in _sValue and there is a _styleChild - * which contains the style element, then the content in style - * element is updated else the _styleChild is set and its content - * is set to an empty string. + * If there is a _styleChild which contains the style element, then + * the content in style element is updated else the _styleChild is + * obtained and its content is set. */ - if (!_sValue.empty() && _styleChild) { - _styleChild->firstChild()->setContent(_sValue.c_str()); + if (_styleChild) { + _updateStyleContent(); } else { - for (unsigned i = 0; i < _num; ++i) { - if (std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style") { - _styleChild = _document->getReprRoot()->nthChild(i); - } - } - _styleChild->firstChild()->setContent(""); + _styleChild = _styleElementNode(); + _updateStyleContent(); } } _store->erase(row); } } +/** + * @brief StyleDialog::_styleElementNode + * @return + * This function returns the node containing style element. The document's + * children are iterated and the repr of the style element that occurs is + * obtained. + */ +Inkscape::XML::Node* StyleDialog::_styleElementNode() +{ + for (unsigned i = 0; i < _num; ++i) { + if (std::string(_document->getReprRoot()->nthChild(i)->name()) + == "svg:style") { + return _document->getReprRoot()->nthChild(i); + } + else { + return NULL; + } + } +} + /** * @brief StyleDialog::_setClassAttribute * @param sel @@ -412,8 +424,8 @@ std::string StyleDialog::_populateTree(std::vectorappend()); row[_mColumns._selectorLabel] = _selectVec[it].first; - std::string selValue = _selectVec[it].first + " { " - + _selectVec[it].second + " }" + "\n"; + std::string selValue = _selectVec[it].first + "{" + + _selectVec[it].second + "}" + "\n"; selectorValue.append(selValue.c_str()); } @@ -421,12 +433,7 @@ std::string StyleDialog::_populateTree(std::vectorset_sensitive(true); } - for (unsigned i = 0; i < _num; ++i) { - if (std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style") { - _styleChild = _document->getReprRoot()->nthChild(i); - } - } + _styleChild = _styleElementNode(); return selectorValue; } @@ -438,9 +445,7 @@ std::string StyleDialog::_populateTree(std::vectortype == GDK_BUTTON_PRESS && event->button == 1) { @@ -461,37 +466,30 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) Gtk::TreeModel::iterator iter = refTreeSelection-> get_selected(); - if (iter) { + if (iter) + { Gtk::TreeModel::Row row = *iter; typedef Gtk::TreeModel::Children type_children; - type_children children = row->children(); Gtk::TreeModel::Row childrow; - - if (children.size() == 0 && row->parent() == 0) { - childrow = *(_store->append(row->children())); - childrow[_mColumns._selectorLabel] = obj->getId(); - childrow[_mColumns._colAddRemove] = false; - childrow[_mColumns._colObj] = obj; - } - else { - for(type_children::iterator it = children.begin(); + path = _treeView.get_model()->get_path(iter); + childrow = *(_store->append(row->children())); + childrow[_mColumns._selectorLabel] = obj->getId(); + childrow[_mColumns._colAddRemove] = false; + childrow[_mColumns._colObj] = obj; + Gtk::TreeModel::Children children = row.children(); + std::string childStyle; + if (children) { + for(Gtk::TreeModel::Children::iterator it = children.begin(); it != children.end(); ++it) { - Gtk::TreeModel::iterator i = it; - path = _treeView.get_model()->get_path(i); - - if((*it)->get_value(_mColumns._selectorLabel) - != obj->getId()) { - childrow = *(_store->append(row.children())); - childrow[_mColumns._selectorLabel] = obj->getId(); - childrow[_mColumns._colAddRemove] = false; - childrow[_mColumns._colObj] = obj; - } - else { - std::cout << "Do nothing" << std::endl; - } + Gtk::TreeModel::Row row = *it; + SPObject *obj = row[_mColumns._colObj]; + childStyle = "#" + std::string(obj->getId()) + "{" + + std::string(obj->getAttribute("style")) + "}\n"; } } + _selectorVec.push_back(std::make_pair(obj->getId(), childStyle)); } + _updateStyleContent(); } } } @@ -506,21 +504,21 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) * selected in the treeview. */ void StyleDialog::_selectedRowCallback(const Gtk::TreeModel::Path& path, - Gtk::TreeViewColumn* /* column */) + Gtk::TreeViewColumn* column ) { _desktop->selection->clear(); - Gtk::TreeModel::iterator iter = _store->get_iter(path); - if (iter) { - Gtk::TreeModel::Row row = *iter; - Gtk::TreeModel::Children children = row.children(); - - if (row[_mColumns._colObj]) { - SPObject *obj = row[_mColumns._colObj]; - _desktop->selection->add(obj); - } - - if (children) { - _checkAllChildren(children); + if (column == _treeView.get_column(1)) { + Gtk::TreeModel::iterator iter = _store->get_iter(path); + if (iter) { + Gtk::TreeModel::Row row = *iter; + Gtk::TreeModel::Children children = row.children(); + if (row[_mColumns._colObj]) { + SPObject *obj = row[_mColumns._colObj]; + _desktop->selection->add(obj); + } + if (children) { + _checkAllChildren(children); + } } } } diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 79897a5b6..4193752e3 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -50,6 +50,8 @@ private: void _selectedRowCallback(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* /* column */); void _checkAllChildren(Gtk::TreeModel::Children& children); + Inkscape::XML::Node *_styleElementNode(); + void _updateStyleContent(); class ModelColumns : public Gtk::TreeModel::ColumnRecord { -- cgit v1.2.3 From 0aca36171bd8c5c33823f839f594b8677d97c51d Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Wed, 29 Jun 2016 05:34:04 -0400 Subject: avoid zero SBasis curve. (Bug 1593963) Fixed bugs: - https://launchpad.net/bugs/1593963 (bzr r15003) --- src/2geom/sbasis-geometric.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/2geom/sbasis-geometric.cpp b/src/2geom/sbasis-geometric.cpp index 19eccc451..3fe27748e 100644 --- a/src/2geom/sbasis-geometric.cpp +++ b/src/2geom/sbasis-geometric.cpp @@ -227,7 +227,7 @@ Geom::unitVector(D2 const &V_in, double tol, unsigned order){ // -This approach is numerically bad. Find a stable way to rescale V_in to have non vanishing ends. // -This done, unitVector will have jumps at zeros: fill the gaps with arcs of circles. D2 V = RescaleForNonVanishingEnds(V_in); - if (V[0].isZero(0) && V[1].isZero(0)) + if (V[0].isZero(tol) && V[1].isZero(tol)) return Piecewise >(D2(Linear(1),SBasis())); SBasis x = V[0], y = V[1]; -- cgit v1.2.3 From cc89ba02cda5257f76df813d86318b57469ee81e Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Thu, 30 Jun 2016 15:02:15 +0530 Subject: If selectors(children) of a row in treeview are deleted, XML repr is updated and also remove duplicate style element(if one already exists) (bzr r14949.1.33) --- src/ui/dialog/styledialog.cpp | 96 ++++++++++++++++++++++++++++--------------- src/ui/dialog/styledialog.h | 2 +- 2 files changed, 65 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 1b93fb550..3b01faa10 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -83,7 +83,7 @@ StyleDialog::StyleDialog() : del = manage( new Gtk::Button() ); _styleButton(*del, "list-remove", "Remove a CSS Selector"); del->signal_clicked().connect(sigc::mem_fun(*this, - &StyleDialog::_delSelector)); + &StyleDialog::_delSelector)); del->set_sensitive(false); _mainBox.pack_end(_buttonBox, Gtk::PACK_SHRINK); @@ -105,7 +105,7 @@ StyleDialog::StyleDialog() : _styleExists = false; _document = _targetDesktop->doc(); _num = _document->getReprRoot()->childCount(); - _sValue = _populateTree(_getSelectorVec()); + _selectorValue = _populateTree(_getSelectorVec()); _treeView.signal_button_press_event().connect(sigc::mem_fun(*this, &StyleDialog:: @@ -172,7 +172,7 @@ void StyleDialog::_addSelector() * with a dot. */ if (!textEditPtr->get_text().empty()) { - _selectorName = textEditPtr->get_text(); + _selectorName = textEditPtr->get_text(); } else { _selectorName = ".Class1"; @@ -199,7 +199,7 @@ void StyleDialog::_addSelector() if (obj->getRepr()->attribute("style")) { for (List iter = obj->getRepr()->attributeList(); - iter; ++iter) { + iter; ++iter) { gchar const * property = g_quark_to_string(iter->key); gchar const * value = iter->value; @@ -256,17 +256,12 @@ void StyleDialog::_addSelector() if (_styleElementNode()) { _styleChild = _styleElementNode(); - _styleExists = true; - } - else { - _styleExists = false; + _updateStyleContent(); } - - if (_styleExists) { + else if (_styleExists && !_newDrawing) { _updateStyleContent(); } - else { - _sValue = _selectorValue; + else if (!_styleExists) { Inkscape::XML::Node *root = _document->getReprDoc()->root(); Inkscape::XML::Node *newChild = _document->getReprDoc() ->createElement("svg:style"); @@ -292,17 +287,16 @@ void StyleDialog::_updateStyleContent() for (unsigned i = 0; i < _selectorVec.size(); ++i) { styleContent = styleContent + _selectorVec[i].second; } - _styleElementNode()->firstChild()->setContent(styleContent.c_str()); + _styleChild->firstChild()->setContent(styleContent.c_str()); } /** * @brief StyleDialog::_delSelector * This function deletes selector when '-' at the bottom is clicked. The index * of selected row is obtained and the corresponding selector and its values are - * deleted from the selector vector. Then _sValue's content is reset and contains - * only selectors remaining in the selVec (or treeview). - * TODO: get index of children of rows for correct deletion of rows having - * children. + * deleted from the selector vector. If a row has no parent, it is directly + * erased from the vector else the string containing selector row's selector value + * is updated after parsing. */ void StyleDialog::_delSelector() { @@ -316,7 +310,37 @@ void StyleDialog::_delSelector() int i = atoi(path.to_string().c_str()); if (_selectorVec.size() != 0) { - _selectorVec.erase(_selectorVec.begin()+i); + if (!row.parent()) { + _selectorVec.erase(_selectorVec.begin()+i); + } + else { + std::stringstream str; + std::string sel, key, value; + int i; + + for (unsigned it = 0; it < _selectorVec.size(); ++it) { + str << _selectorVec[it].second; + i = it; + } + + while (std::getline(str, sel, '\n')) { + REMOVE_SPACES(sel); + if (!sel.empty()) { + key = strtok(strdup(sel.c_str()), "{"); + char *temp = strtok(NULL, "}"); + if (strtok(temp, "}") != NULL) { + value = strtok(temp, "}"); + } + if (key == "#" + row[_mColumns._selectorLabel]) { + sel = ""; + } + else { + sel = sel; + } + _selectorVec[i].second = sel; + } + } + } /** * If there is a _styleChild which contains the style element, then @@ -347,6 +371,8 @@ Inkscape::XML::Node* StyleDialog::_styleElementNode() for (unsigned i = 0; i < _num; ++i) { if (std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style") { + _styleExists = true; + _newDrawing = true; return _document->getReprRoot()->nthChild(i); } else { @@ -376,15 +402,17 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) * @return selVec * This function returns a vector whose key is the style selector name and value * is the style properties. All style selectors are extracted from svg:style - * element. + * element. _newDrawing is flag is set to false check if an existing drawing is + * opened. */ std::vector >StyleDialog::_getSelectorVec() { std::string key, value; - std::vector > selVec; - for (unsigned i = 0; i < _num; ++i) { if (std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style") { + _styleExists = true; + _newDrawing = false; + _styleChild = _document->getReprRoot()->nthChild(i); std::stringstream str; str << _document->getReprRoot()->nthChild(i)->firstChild()->content(); std::string sel; @@ -401,12 +429,12 @@ std::vector >StyleDialog::_getSelectorVec() if (strtok(temp, "}") != NULL) { value = strtok(temp, "}"); } - selVec.push_back(std::make_pair(key, value)); + _selectorVec.push_back(std::make_pair(key, sel)); } } } } - return selVec; + return _selectorVec; } /** @@ -418,23 +446,21 @@ std::vector >StyleDialog::_getSelectorVec() std::string StyleDialog::_populateTree(std::vector > _selVec) { - std::vector > _selectVec = _selVec; + _selectorVec = _selVec; std::string selectorValue; - for(unsigned it = 0; it < _selectVec.size(); ++it) { + for(unsigned it = 0; it < _selectorVec.size(); ++it) { Gtk::TreeModel::Row row = *(_store->append()); - row[_mColumns._selectorLabel] = _selectVec[it].first; - std::string selValue = _selectVec[it].first + "{" - + _selectVec[it].second + "}" + "\n"; + row[_mColumns._selectorLabel] = _selectorVec[it].first; + _selectorVec[it].second = _selectorVec[it].second + "\n"; + std::string selValue = _selectorVec[it].second; selectorValue.append(selValue.c_str()); } - if (_selectVec.size() > 0) { + if (_selectorVec.size() > 0) { del->set_sensitive(true); } - _styleChild = _styleElementNode(); - return selectorValue; } @@ -489,7 +515,13 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) } _selectorVec.push_back(std::make_pair(obj->getId(), childStyle)); } - _updateStyleContent(); + if (_styleElementNode()) { + _styleChild = _styleElementNode(); + _updateStyleContent(); + } + else if (_styleExists && !_newDrawing) { + _updateStyleContent(); + } } } } diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 4193752e3..fef1a954b 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -75,12 +75,12 @@ private: Gtk::Button* create; SPDocument* _document; bool _styleExists; - std::string _sValue ; Inkscape::XML::Node *_styleChild; unsigned _num; std::string _selectorName = ""; std::string _selectorValue; Gtk::TreeModel::Row _row; + bool _newDrawing; // Signal handlers void _addSelector(); -- cgit v1.2.3 From 0af04b99d1160cf2cfc38adb3a0f74c185da4370 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Thu, 30 Jun 2016 18:43:15 +0530 Subject: Solve some compiler errors (bzr r14949.1.34) --- src/ui/dialog/styledialog.cpp | 12 +++++------- src/ui/dialog/styledialog.h | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 3b01faa10..3d2091aef 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -316,11 +316,11 @@ void StyleDialog::_delSelector() else { std::stringstream str; std::string sel, key, value; - int i; + int index; for (unsigned it = 0; it < _selectorVec.size(); ++it) { str << _selectorVec[it].second; - i = it; + index = it; } while (std::getline(str, sel, '\n')) { @@ -337,7 +337,7 @@ void StyleDialog::_delSelector() else { sel = sel; } - _selectorVec[i].second = sel; + _selectorVec[index].second = sel; } } } @@ -375,10 +375,8 @@ Inkscape::XML::Node* StyleDialog::_styleElementNode() _newDrawing = true; return _document->getReprRoot()->nthChild(i); } - else { - return NULL; - } } + return NULL; } /** @@ -495,7 +493,6 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) if (iter) { Gtk::TreeModel::Row row = *iter; - typedef Gtk::TreeModel::Children type_children; Gtk::TreeModel::Row childrow; path = _treeView.get_model()->get_path(iter); childrow = *(_store->append(row->children())); @@ -527,6 +524,7 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) } } } + return false; } /** diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index fef1a954b..0192b3987 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -77,7 +77,7 @@ private: bool _styleExists; Inkscape::XML::Node *_styleChild; unsigned _num; - std::string _selectorName = ""; + std::string _selectorName; std::string _selectorValue; Gtk::TreeModel::Row _row; bool _newDrawing; -- cgit v1.2.3 From 2c22c31cb8650ad49f5e83c9221524f4cdcd3ddd Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 1 Jul 2016 12:37:35 +0530 Subject: Solve a spacing issue & fix buttons to add selectors when existing drawing is opened (bzr r14949.1.35) --- src/ui/dialog/styledialog.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 3d2091aef..3ee0e44f7 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -20,7 +20,7 @@ using Inkscape::Util::List; using Inkscape::XML::AttributeRecord; -#define REMOVE_SPACES(x) x.erase(std::remove(x.begin(), x.end(), ' '), x.end()); +#define REMOVE_SPACES(x) x.erase(0, x.find_first_not_of(' ')); namespace Inkscape { namespace UI { @@ -450,6 +450,7 @@ std::string StyleDialog::_populateTree(std::vectorappend()); row[_mColumns._selectorLabel] = _selectorVec[it].first; + row[_mColumns._colAddRemove] = true; _selectorVec[it].second = _selectorVec[it].second + "\n"; std::string selValue = _selectorVec[it].second; selectorValue.append(selValue.c_str()); -- cgit v1.2.3 From 7c35f8e864197a1b2620a5337947bcdfd0b52d5a Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 1 Jul 2016 17:19:45 +0530 Subject: Add support to select corresponding treeview rows when objects are selected (bzr r14949.1.36) --- src/ui/dialog/styledialog.cpp | 55 ++++++++++++++++++++++++++++++++++++------- src/ui/dialog/styledialog.h | 8 ++++--- 2 files changed, 52 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 3ee0e44f7..406b984d7 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -20,7 +20,8 @@ using Inkscape::Util::List; using Inkscape::XML::AttributeRecord; -#define REMOVE_SPACES(x) x.erase(0, x.find_first_not_of(' ')); +#define REMOVE_SPACES(x) x.erase(0, x.find_first_not_of(' ')); \ + x.erase(x.find_last_not_of(' ') + 1); namespace Inkscape { namespace UI { @@ -126,6 +127,8 @@ void StyleDialog::setDesktop( SPDesktop* desktop ) { Panel::setDesktop(desktop); _desktop = Panel::getDesktop(); + _desktop->selection->connectChanged(sigc::mem_fun(*this, &StyleDialog:: + _selectRow)); } /** @@ -189,6 +192,7 @@ void StyleDialog::_addSelector() * class attribute for the selected object is set too. */ SPObject *obj; + SPObject *selectorObj; bool objExists = false; if (!_desktop->getSelection()->list().empty()) { std::vector selected = _desktop->getSelection()->list(); @@ -241,6 +245,7 @@ void StyleDialog::_addSelector() _row[_mColumns._colAddRemove] = true; if (objExists) { _row[_mColumns._colObj] = obj; + selectorObj = obj; } break; default: @@ -252,7 +257,8 @@ void StyleDialog::_addSelector() * from selectorValue above. If style element already exists, then * the new selector's content is appended to its previous content. */ - _selectorVec.push_back(std::make_pair(_selectorName, _selectorValue)); + _selectorVec.push_back(std::make_pair(std::make_pair(_selectorName, selectorObj), + _selectorValue)); if (_styleElementNode()) { _styleChild = _styleElementNode(); @@ -403,7 +409,7 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) * element. _newDrawing is flag is set to false check if an existing drawing is * opened. */ -std::vector >StyleDialog::_getSelectorVec() +std::vector, std::string> > StyleDialog::_getSelectorVec() { std::string key, value; for (unsigned i = 0; i < _num; ++i) { @@ -427,7 +433,12 @@ std::vector >StyleDialog::_getSelectorVec() if (strtok(temp, "}") != NULL) { value = strtok(temp, "}"); } - _selectorVec.push_back(std::make_pair(key, sel)); + std::string selId = key.erase(0, key.find_first_not_of('#')); + REMOVE_SPACES(selId); + REMOVE_SPACES(key); + SPObject *obj = _document->getObjectById(selId); + _selectorVec.push_back(std::make_pair(std::make_pair(key, obj), + sel)); } } } @@ -441,16 +452,17 @@ std::vector >StyleDialog::_getSelectorVec() * This function populates the treeview with selectors available in the * stylesheet. */ -std::string StyleDialog::_populateTree(std::vector > _selVec) +std::string StyleDialog::_populateTree(std::vector, std::string> > _selVec) { _selectorVec = _selVec; std::string selectorValue; for(unsigned it = 0; it < _selectorVec.size(); ++it) { Gtk::TreeModel::Row row = *(_store->append()); - row[_mColumns._selectorLabel] = _selectorVec[it].first; + row[_mColumns._selectorLabel] = _selectorVec[it].first.first; row[_mColumns._colAddRemove] = true; + row[_mColumns._colObj] = _selectorVec[it].first.second; _selectorVec[it].second = _selectorVec[it].second + "\n"; std::string selValue = _selectorVec[it].second; selectorValue.append(selValue.c_str()); @@ -511,7 +523,9 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) std::string(obj->getAttribute("style")) + "}\n"; } } - _selectorVec.push_back(std::make_pair(obj->getId(), childStyle)); + _selectorVec.push_back(std::make_pair(std::make_pair + (obj->getId(), obj), + childStyle)); } if (_styleElementNode()) { _styleChild = _styleElementNode(); @@ -572,6 +586,31 @@ void StyleDialog::_checkAllChildren(Gtk::TreeModel::Children& children) } } +/** + * @brief StyleDialog::_selectRow + * This function selects the rows in treeview corresponding to an object selected + * in the drawing. + */ +void StyleDialog::_selectRow(Selection */*sel*/) +{ + if (!_desktop->selection->list().empty()) { + SPObject *obj; + std::vector selected = _desktop->getSelection()->list(); + for (unsigned i = 0; i < selected.size(); ++i) { + obj = selected.at(i); + } + + Gtk::TreeModel::Children children = _store->children(); + for(Gtk::TreeModel::Children::iterator iter = children.begin(); + iter != children.end(); ++iter) { + Gtk::TreeModel::Row row = *iter; + if (obj == row[_mColumns._colObj]) { + _treeView.get_selection()->select(row); + } + } + } +} + } // namespace Dialog } // namespace UI } // namespace Inkscape diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 0192b3987..6e1ffbb2c 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -43,15 +43,17 @@ public: private: void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); std::string _setClassAttribute(std::vector); - std::vector >_selectorVec; - std::vector > _getSelectorVec(); - std::string _populateTree(std::vector >); + std::vector, std::string> >_selectorVec; + std::vector, std::string> > _getSelectorVec(); + std::string _populateTree(std::vector, + std::string> >); bool _handleButtonEvent(GdkEventButton *event); void _selectedRowCallback(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* /* column */); void _checkAllChildren(Gtk::TreeModel::Children& children); Inkscape::XML::Node *_styleElementNode(); void _updateStyleContent(); + void _selectRow(Selection *); class ModelColumns : public Gtk::TreeModel::ColumnRecord { -- cgit v1.2.3 From 22262f2db6747eb516283b92abcfd348c700911a Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Fri, 1 Jul 2016 20:57:32 +0200 Subject: Added xmlNodes as range function (bzr r14954.1.12) --- src/object-set.cpp | 9 ++----- src/object-set.h | 45 +++++++++++++++++++++++---------- src/selection-chemistry.cpp | 20 +++++++-------- src/splivarot.cpp | 2 +- src/ui/dialog/export.cpp | 9 +++---- src/ui/dialog/filter-effects-dialog.cpp | 2 +- 6 files changed, 50 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/object-set.cpp b/src/object-set.cpp index 518ce15a3..1240e5198 100644 --- a/src/object-set.cpp +++ b/src/object-set.cpp @@ -15,6 +15,8 @@ #include "box3d.h" #include "persp3d.h" #include "preferences.h" +#include +#include namespace Inkscape { @@ -233,13 +235,6 @@ std::vector ObjectSet::items() { return result; } -std::vector ObjectSet::xmlNodes() { - std::vector list = items(); - std::vector result; - std::transform(list.begin(), list.end(), std::back_inserter(result), [](SPItem* item) { return item->getRepr(); }); - return result; -} - Inkscape::XML::Node *ObjectSet::singleRepr() { SPObject *obj = single(); return obj ? obj->getRepr() : nullptr; diff --git a/src/object-set.h b/src/object-set.h index 29083863b..ea6534350 100644 --- a/src/object-set.h +++ b/src/object-set.h @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,6 +41,26 @@ class Node; struct hashed{}; struct random_access{}; +struct is_item { + bool operator()(SPObject* obj) { + return SP_IS_ITEM(obj); + } +}; + +struct object_to_item { + typedef SPItem* result_type; + SPItem* operator()(SPObject* obj) const { + return SP_ITEM(obj); + } +}; + +struct object_to_node { + typedef XML::Node* result_type; + XML::Node* operator()(SPObject* obj) const { + return obj->getRepr(); + } +}; + typedef boost::multi_index_container< SPObject*, boost::multi_index::indexed_by< @@ -56,21 +78,11 @@ typedef boost::any_range< SPObject* const&, std::ptrdiff_t> SPObjectRange; -typedef boost::any_range< - SPItem*, - boost::random_access_traversal_tag, - SPItem* const&, - std::ptrdiff_t> SPItemRange; - -typedef boost::any_range< - XML::Node*, - boost::random_access_traversal_tag, - XML::Node* const&, - std::ptrdiff_t> XMLNodeRange; - class ObjectSet { public: enum CompareSize {HORIZONTAL, VERTICAL, AREA}; + typedef decltype(multi_index_container().get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_item())) SPItemRange; + typedef decltype(multi_index_container().get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_node())) XMLNodeRange; ObjectSet() {}; virtual ~ObjectSet(); @@ -169,7 +181,11 @@ public: std::vector items(); /** Returns a list of the xml nodes of all selected objects. */ - std::vector xmlNodes(); + XMLNodeRange xmlNodes() { + return XMLNodeRange(container.get() + | boost::adaptors::filtered(is_item()) + | boost::adaptors::transformed(object_to_node())); + } /** * Returns a single selected object's xml node. @@ -255,6 +271,9 @@ protected: }; +typedef ObjectSet::SPItemRange SPItemRange; +typedef ObjectSet::XMLNodeRange XMLNodeRange; + } // namespace Inkscape #endif //INKSCAPE_PROTOTYPE_OBJECTSET_H diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index ded776fea..82f89c03a 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -454,7 +454,7 @@ void sp_selection_duplicate(SPDesktop *desktop, bool suppressDone, bool duplicat desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to duplicate.")); return; } - std::vector reprs(selection->xmlNodes()); + std::vector reprs(selection->xmlNodes().begin(), selection->xmlNodes().end()); if(duplicateLayer){ reprs.clear(); @@ -763,7 +763,7 @@ void sp_selection_group(Inkscape::Selection *selection, SPDesktop *desktop) return; } - std::vector p (selection->xmlNodes()); + std::vector p (selection->xmlNodes().begin(), selection->xmlNodes().end()); selection->clear(); @@ -1048,7 +1048,7 @@ void sp_selection_raise_to_top(Inkscape::Selection *selection, SPDesktop *deskto return; } - std::vector rl(selection->xmlNodes()); + std::vector rl(selection->xmlNodes().begin(), selection->xmlNodes().end()); sort(rl.begin(),rl.end(),sp_repr_compare_position_bool); for (std::vector::const_iterator l=rl.begin(); l!=rl.end();++l) { @@ -1132,7 +1132,7 @@ void sp_selection_lower_to_bottom(Inkscape::Selection *selection, SPDesktop *des return; } - std::vector rl(selection->xmlNodes()); + std::vector rl(selection->xmlNodes().begin(), selection->xmlNodes().end()); sort(rl.begin(),rl.end(),sp_repr_compare_position_bool); for (std::vector::const_reverse_iterator l=rl.rbegin();l!=rl.rend();++l) { @@ -1722,8 +1722,8 @@ void sp_selection_remove_transform(SPDesktop *desktop) Inkscape::Selection *selection = desktop->getSelection(); - std::vector items = selection->xmlNodes(); - for (std::vector::const_iterator l=items.begin();l!=items.end() ;++l) { + auto items = selection->xmlNodes(); + for (auto l=items.begin();l!=items.end() ;++l) { (*l)->setAttribute("transform", NULL, false); } @@ -2603,7 +2603,7 @@ void sp_selection_clone(SPDesktop *desktop) return; } - std::vector reprs (selection->xmlNodes()); + std::vector reprs(selection->xmlNodes().begin(), selection->xmlNodes().end()); selection->clear(); @@ -3472,12 +3472,12 @@ void sp_selection_get_export_hints(Inkscape::Selection *selection, Glib::ustring return; } - std::vector const reprlst = selection->xmlNodes(); + auto reprlst = selection->xmlNodes(); bool filename_search = TRUE; bool xdpi_search = TRUE; bool ydpi_search = TRUE; - for (std::vector::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();++i){ + for (auto i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();++i){ gchar const *dpi_string; Inkscape::XML::Node *repr = *i; @@ -3765,7 +3765,7 @@ void sp_selection_set_clipgroup(SPDesktop *desktop) return; } - std::vector p(selection->xmlNodes()); + std::vector p(selection->xmlNodes().begin(), selection->xmlNodes().end()); sort(p.begin(),p.end(),sp_repr_compare_position_bool); diff --git a/src/splivarot.cpp b/src/splivarot.cpp index d4ef3f9c2..09d74a010 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -689,7 +689,7 @@ sp_selected_path_boolop(Inkscape::Selection *selection, SPDesktop *desktop, bool } } else { // find out the bottom object - std::vector sorted(selection->xmlNodes()); + std::vector sorted(selection->xmlNodes().begin(), selection->xmlNodes().end()); sort(sorted.begin(),sorted.end(),sp_repr_compare_position_bool); diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 6d2842511..dbee80af9 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -820,8 +820,8 @@ void Export::onAreaToggled () one that's nice */ if (filename.empty()) { const gchar * id = "object"; - const std::vector reprlst = SP_ACTIVE_DESKTOP->getSelection()->xmlNodes(); - for(std::vector::const_iterator i=reprlst.begin(); reprlst.end() != i; ++i) { + auto reprlst = SP_ACTIVE_DESKTOP->getSelection()->xmlNodes(); + for(auto i=reprlst.begin(); reprlst.end() != i; ++i) { Inkscape::XML::Node * repr = *i; if (repr->attribute("id")) { id = repr->attribute("id"); @@ -1231,15 +1231,14 @@ void Export::onExport () break; } case SELECTION_SELECTION: { - std::vector reprlst; SPDocument * doc = SP_ACTIVE_DOCUMENT; bool modified = false; bool saved = DocumentUndo::getUndoSensitive(doc); DocumentUndo::setUndoSensitive(doc, false); - reprlst = desktop->getSelection()->xmlNodes(); + auto reprlst = desktop->getSelection()->xmlNodes(); - for(std::vector::const_iterator i=reprlst.begin(); reprlst.end() != i; ++i) { + for(auto i=reprlst.begin(); reprlst.end() != i; ++i) { Inkscape::XML::Node * repr = *i; const gchar * temp_string; Glib::ustring dir = Glib::path_get_dirname(filename.c_str()); diff --git a/src/ui/dialog/filter-effects-dialog.cpp b/src/ui/dialog/filter-effects-dialog.cpp index dfc19f3cc..ccba5a278 100644 --- a/src/ui/dialog/filter-effects-dialog.cpp +++ b/src/ui/dialog/filter-effects-dialog.cpp @@ -691,7 +691,7 @@ private: void select_svg_element(){ Inkscape::Selection* sel = _desktop->getSelection(); if (sel->isEmpty()) return; - Inkscape::XML::Node* node = sel->xmlNodes()[0]; + Inkscape::XML::Node* node = sel->xmlNodes().front(); if (!node || !node->matchAttributeName("id")) return; std::ostringstream xlikhref; -- cgit v1.2.3 From 30e74d438ef362634967a47053ecf27fb950e340 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 2 Jul 2016 02:27:56 +0200 Subject: Fix bug #1598009 regression on path parameter Fixed bugs: - https://launchpad.net/bugs/1598009 (bzr r15004) --- src/live_effects/parameter/path.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index bed191e83..f0c494267 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -237,7 +237,6 @@ PathParam::param_editOncanvas(SPItem *item, SPDesktop * dt) r.role = SHAPE_ROLE_LPE_PARAM; r.edit_transform = item->i2dt_affine(); // TODO is it right? - r.edit_transform *= item->transform.inverse(); if (!href) { r.item = reinterpret_cast(param_effect->getLPEObj()); r.lpe_key = param_key; @@ -458,8 +457,7 @@ PathParam::paste_param_path(const char *svgd) SPItem * item = SP_ACTIVE_DESKTOP->getSelection()->singleItem(); if (item != NULL) { Geom::PathVector path_clipboard = sp_svg_read_pathv(svgd); - path_clipboard *= item->i2doc_affine().inverse() * item->transform; - path_clipboard *= Geom::Translate(path_clipboard.initialPoint() - _pathvector.initialPoint()).inverse(); + path_clipboard *= item->i2doc_affine().inverse(); svgd = sp_svg_write_path( path_clipboard ); } -- cgit v1.2.3 From fefc3d571319771e1ee9e6c6f161d29882e7d7ab Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sat, 2 Jul 2016 14:48:19 +0200 Subject: Fix typo from GList purge that broke SVG Font Editor dialog. (bzr r15005) --- src/ui/dialog/svg-fonts-dialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index 790c0e5fb..e96eec5bb 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -266,7 +266,7 @@ void SvgFontsDialog::update_fonts() { SPDesktop* desktop = this->getDesktop(); SPDocument* document = desktop->getDocument(); - std::vector fonts = document->getResourceList( "fonts" ); + std::vector fonts = document->getResourceList( "font" ); _model->clear(); for (std::vector::const_iterator it = fonts.begin(); it != fonts.end(); ++it) { -- cgit v1.2.3 From aeb705274cc983200011d453643d5e3a6d2fd5f9 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sat, 2 Jul 2016 15:53:33 +0200 Subject: Rename function, fix some indenting issues. (bzr r15006) --- src/ui/dialog/svg-fonts-dialog.cpp | 4 +- src/ui/dialog/svg-fonts-dialog.h | 206 +++++++++++++++++++------------------ 2 files changed, 110 insertions(+), 100 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index e96eec5bb..a39955123 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -340,7 +340,7 @@ void SvgFontsDialog::on_font_selection_changed(){ update_sensitiveness(); } -void SvgFontsDialog::on_setwidth_changed(){ +void SvgFontsDialog::on_setfontdata_changed(){ SPFont* spfont = this->get_selected_spfont(); if (spfont){ spfont->horiz_adv_x = setwidth_spin.get_value(); @@ -397,7 +397,7 @@ Gtk::VBox* SvgFontsDialog::global_settings_tab(){ setwidth_hbox->add(*Gtk::manage(new Gtk::Label(_("Set width:")))); setwidth_hbox->add(setwidth_spin); - setwidth_spin.signal_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::on_setwidth_changed)); + setwidth_spin.signal_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::on_setfontdata_changed)); setwidth_spin.set_range(0, 4096); setwidth_spin.set_increments(10, 0); global_vbox.pack_start(*setwidth_hbox, false, false); diff --git a/src/ui/dialog/svg-fonts-dialog.h b/src/ui/dialog/svg-fonts-dialog.h index e5c4631e4..e80bbfd39 100644 --- a/src/ui/dialog/svg-fonts-dialog.h +++ b/src/ui/dialog/svg-fonts-dialog.h @@ -69,64 +69,63 @@ public: SvgFontsDialog(); ~SvgFontsDialog(); - static SvgFontsDialog &getInstance() - { return *new SvgFontsDialog(); } + static SvgFontsDialog &getInstance() { return *new SvgFontsDialog(); } void update_fonts(); SvgFont* get_selected_svgfont(); SPFont* get_selected_spfont(); - SPGlyph* get_selected_glyph(); - SPGlyphKerning* get_selected_kerning_pair(); + SPGlyph* get_selected_glyph(); + SPGlyphKerning* get_selected_kerning_pair(); - //TODO: these methods should be private, right?! + //TODO: these methods should be private, right?! void on_font_selection_changed(); - void on_kerning_pair_selection_changed(); + void on_kerning_pair_selection_changed(); void on_preview_text_changed(); void on_kerning_pair_changed(); void on_kerning_value_changed(); - void on_setwidth_changed(); - void add_font(); - Geom::PathVector flip_coordinate_system(Geom::PathVector pathv); + void on_setfontdata_changed(); + void add_font(); + Geom::PathVector flip_coordinate_system(Geom::PathVector pathv); - //TODO: AttrEntry is currently unused. Should we remove it? + //TODO: AttrEntry is currently unused. Should we remove it? class AttrEntry : public Gtk::HBox - { - public: - AttrEntry(SvgFontsDialog* d, gchar* lbl, const SPAttributeEnum attr); - void set_text(char*); - private: - SvgFontsDialog* dialog; - void on_attr_changed(); - Gtk::Entry entry; - SPAttributeEnum attr; + { + public: + AttrEntry(SvgFontsDialog* d, gchar* lbl, const SPAttributeEnum attr); + void set_text(char*); + private: + SvgFontsDialog* dialog; + void on_attr_changed(); + Gtk::Entry entry; + SPAttributeEnum attr; }; private: - void update_glyphs(); - void update_sensitiveness(); - void update_global_settings_tab(); - void populate_glyphs_box(); + void update_glyphs(); + void update_sensitiveness(); + void update_global_settings_tab(); + void populate_glyphs_box(); void populate_kerning_pairs_box(); - void set_glyph_description_from_selected_path(); - void missing_glyph_description_from_selected_path(); - void reset_missing_glyph_description(); - void add_glyph(); - void glyph_unicode_edit(const Glib::ustring&, const Glib::ustring&); - void glyph_name_edit(const Glib::ustring&, const Glib::ustring&); - void remove_selected_glyph(); - void remove_selected_font(); - void remove_selected_kerning_pair(); + void set_glyph_description_from_selected_path(); + void missing_glyph_description_from_selected_path(); + void reset_missing_glyph_description(); + void add_glyph(); + void glyph_unicode_edit(const Glib::ustring&, const Glib::ustring&); + void glyph_name_edit(const Glib::ustring&, const Glib::ustring&); + void remove_selected_glyph(); + void remove_selected_font(); + void remove_selected_kerning_pair(); - void add_kerning_pair(); + void add_kerning_pair(); - void create_glyphs_popup_menu(Gtk::Widget& parent, sigc::slot rem); - void glyphs_list_button_release(GdkEventButton* event); + void create_glyphs_popup_menu(Gtk::Widget& parent, sigc::slot rem); + void glyphs_list_button_release(GdkEventButton* event); - void create_fonts_popup_menu(Gtk::Widget& parent, sigc::slot rem); - void fonts_list_button_release(GdkEventButton* event); + void create_fonts_popup_menu(Gtk::Widget& parent, sigc::slot rem); + void fonts_list_button_release(GdkEventButton* event); - void create_kerning_pairs_popup_menu(Gtk::Widget& parent, sigc::slot rem); - void kerning_pairs_list_button_release(GdkEventButton* event); + void create_kerning_pairs_popup_menu(Gtk::Widget& parent, sigc::slot rem); + void kerning_pairs_list_button_release(GdkEventButton* event); Inkscape::XML::SignalObserver _defs_observer; //in order to update fonts Inkscape::XML::SignalObserver _glyphs_observer; @@ -134,47 +133,47 @@ private: Gtk::HBox* AttrCombo(gchar* lbl, const SPAttributeEnum attr); // Gtk::HBox* AttrSpin(gchar* lbl, const SPAttributeEnum attr); Gtk::VBox* global_settings_tab(); - AttrEntry* _familyname_entry; + AttrEntry* _familyname_entry; Gtk::VBox* kerning_tab(); Gtk::VBox* glyphs_tab(); Gtk::Button _add; Gtk::Button add_glyph_button; - Gtk::Button glyph_from_path_button; - Gtk::Button missing_glyph_button; - Gtk::Button missing_glyph_reset_button; + Gtk::Button glyph_from_path_button; + Gtk::Button missing_glyph_button; + Gtk::Button missing_glyph_reset_button; class Columns : public Gtk::TreeModel::ColumnRecord - { - public: - Columns() - { - add(spfont); - add(svgfont); - add(label); - } - - Gtk::TreeModelColumn spfont; - Gtk::TreeModelColumn svgfont; - Gtk::TreeModelColumn label; + { + public: + Columns() + { + add(spfont); + add(svgfont); + add(label); + } + + Gtk::TreeModelColumn spfont; + Gtk::TreeModelColumn svgfont; + Gtk::TreeModelColumn label; }; Glib::RefPtr _model; Columns _columns; Gtk::TreeView _FontsList; class GlyphsColumns : public Gtk::TreeModel::ColumnRecord - { - public: - GlyphsColumns() - { - add(glyph_node); - add(glyph_name); - add(unicode); - } - - Gtk::TreeModelColumn glyph_node; - Gtk::TreeModelColumn glyph_name; - Gtk::TreeModelColumn unicode; + { + public: + GlyphsColumns() + { + add(glyph_node); + add(glyph_name); + add(unicode); + } + + Gtk::TreeModelColumn glyph_node; + Gtk::TreeModelColumn glyph_name; + Gtk::TreeModelColumn unicode; }; GlyphsColumns _GlyphsListColumns; Glib::RefPtr _GlyphsListStore; @@ -182,30 +181,30 @@ private: Gtk::ScrolledWindow _GlyphsListScroller; class KerningPairColumns : public Gtk::TreeModel::ColumnRecord - { - public: - KerningPairColumns() - { - add(first_glyph); - add(second_glyph); - add(kerning_value); - add(spnode); - } - - Gtk::TreeModelColumn first_glyph; - Gtk::TreeModelColumn second_glyph; - Gtk::TreeModelColumn kerning_value; - Gtk::TreeModelColumn spnode; + { + public: + KerningPairColumns() + { + add(first_glyph); + add(second_glyph); + add(kerning_value); + add(spnode); + } + + Gtk::TreeModelColumn first_glyph; + Gtk::TreeModelColumn second_glyph; + Gtk::TreeModelColumn kerning_value; + Gtk::TreeModelColumn spnode; }; KerningPairColumns _KerningPairsListColumns; Glib::RefPtr _KerningPairsListStore; Gtk::TreeView _KerningPairsList; Gtk::ScrolledWindow _KerningPairsListScroller; - Gtk::Button add_kernpair_button; + Gtk::Button add_kernpair_button; Gtk::VBox _font_settings; - Gtk::VBox global_vbox; - Gtk::VBox glyphs_vbox; + Gtk::VBox global_vbox; + Gtk::VBox glyphs_vbox; Gtk::VBox kerning_vbox; Gtk::Entry _preview_entry; @@ -225,20 +224,20 @@ private: #endif class EntryWidget : public Gtk::HBox - { - public: - EntryWidget() - { - this->add(this->_label); - this->add(this->_entry); - } - void set_label(const gchar* l){ - this->_label.set_text(l); - } - private: - Gtk::Label _label; - Gtk::Entry _entry; - }; + { + public: + EntryWidget() + { + this->add(this->_label); + this->add(this->_entry); + } + void set_label(const gchar* l){ + this->_label.set_text(l); + } + private: + Gtk::Label _label; + Gtk::Entry _entry; + }; EntryWidget _font_family, _font_variant; }; @@ -247,3 +246,14 @@ private: } // namespace Inkscape #endif //#ifndef INKSCAPE_UI_DIALOG_SVG_FONTS_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 495ac0773c4341589f1cd9108c9de3daf5b78c2c Mon Sep 17 00:00:00 2001 From: Sebastian Faubel Date: Sat, 2 Jul 2016 19:15:39 +0200 Subject: Merge with trunk. (bzr r15002.1.1) --- src/CMakeLists.txt | 64 ++++++++++++++++++++---------------------------------- 1 file changed, 24 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 66f16b7fb..d979d7c13 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,10 +2,6 @@ # Define the main source # ----------------------------------------------------------------------------- -set(main_SRC - main.cpp -) - set(sp_SRC attribute-rel-css.cpp attribute-rel-svg.cpp @@ -423,21 +419,6 @@ set(inkscape_SRC version.h ) -if(WIN32) - list(APPEND inkscape_SRC - inkscape.rc - registrytool.cpp - #deptool.cpp - winconsole.cpp - winmain.cpp - - # ------- - # Headers - registrytool.h - ) -endif() - - # ----------------------------------------------------------------------------- # Generate version file # ----------------------------------------------------------------------------- @@ -481,7 +462,6 @@ add_subdirectory(widgets) add_subdirectory(xml) add_subdirectory(2geom) - # Directories containing lists files that describe building internal libraries add_subdirectory(libavoid) add_subdirectory(libcola) @@ -494,7 +474,6 @@ add_subdirectory(livarot) add_subdirectory(libnrtype) add_subdirectory(libdepixelize) - get_property(inkscape_global_SRC GLOBAL PROPERTY inkscape_global_SRC) set(inkscape_SRC @@ -508,12 +487,32 @@ set(inkscape_SRC #add_inkscape_lib(sp_LIB "${sp_SRC}") #add_inkscape_lib(inkscape_LIB "${inkscape_SRC}") +if(WIN32) + # Sources for the inkscape executable on Windows. + set(main_SRC + registrytool.h + registrytool.cpp + main.cpp + winmain.cpp + #winconsole.cpp + ) + + # Add the platform specific resource files (enabling the app icon). + if(${HAVE_MINGW64}) + list(APPEND main_SRC inkscape-x64.rc) + else() + list(APPEND main_SRC inkscape.rc) + endif() +else() + set(main_SRC main.cpp) +endif() + # Build everything except main and inkview.c in a shared library. add_library(inkscape_base SHARED ${inkscape_SRC} ${sp_SRC}) # make executables for inkscape and inkview -add_executable(inkscape ${main_SRC} ) -add_executable(inkview inkview.cpp ) +add_executable(inkscape ${main_SRC}) +add_executable(inkview inkview.cpp) add_dependencies(inkscape inkscape_version) @@ -525,11 +524,9 @@ set(INKSCAPE_TARGET_LIBS # order from automake #sp_LIB #nrtype_LIB - #inkscape_LIB #sp_LIB # annoying, we need both! nrtype_LIB # annoying, we need both! - croco_LIB avoid_LIB cola_LIB @@ -548,22 +545,9 @@ if (NOT "${WITH_EXT_GDL}") list (INSERT INKSCAPE_TARGET_LIBS 0 "gdl_LIB") endif() - - - # Link the inkscape_base library against all external dependencies target_link_libraries(inkscape_base ${INKSCAPE_TARGET_LIBS}) # Link inkscape and inkview against inkscape_base -target_link_libraries(inkscape inkscape_base ) -target_link_libraries(inkview inkscape_base) - -#Define the installation -install( - TARGETS inkscape_base inkscape inkview - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib/inkscape - ARCHIVE DESTINATION lib/inkscape - ) - - +target_link_libraries(inkscape inkscape_base) +target_link_libraries(inkview inkscape_base) \ No newline at end of file -- cgit v1.2.3 From f5c74e3a9d4e23e6cc86851b426dd05958e907ee Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 4 Jul 2016 14:30:44 +0200 Subject: Prevent data-losing crash when sorting attributes and Layer dialog open. (bzr r15007) --- src/attribute-sort-util.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/attribute-sort-util.cpp b/src/attribute-sort-util.cpp index d0f45c418..5c01f7914 100644 --- a/src/attribute-sort-util.cpp +++ b/src/attribute-sort-util.cpp @@ -105,12 +105,17 @@ void sp_attribute_sort_element(Node *repr) { //for (auto it: my_list) { for (std::vector >::iterator it = my_list.begin(); it != my_list.end(); ++it) { - repr->setAttribute( it->first.c_str(), NULL, false ); + // Removing "inkscape:label" results in crash when Layers dialog is open. + if (it->first != "inkscape:label") { + repr->setAttribute( it->first.c_str(), NULL, false ); + } } // Insert all attributes in proper order for (std::vector >::iterator it = my_list.begin(); it != my_list.end(); ++it) { - repr->setAttribute( it->first.c_str(), it->second.c_str(), false ); + if (it->first != "inkscape:label") { + repr->setAttribute( it->first.c_str(), it->second.c_str(), false ); + } } } -- cgit v1.2.3 From be79b33c0c55628f347f2a8418cbd54997050920 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 4 Jul 2016 16:47:05 +0200 Subject: Fix typo that prevents reading of 'units-per-em'. (bzr r15008) --- src/ui/dialog/svg-fonts-dialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index a39955123..08ebbcf14 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -497,7 +497,7 @@ SvgFontsDialog::flip_coordinate_system(Geom::PathVector pathv){ for (obj = get_selected_spfont()->children; obj; obj=obj->next){ if (SP_IS_FONTFACE(obj)){ //XML Tree being directly used here while it shouldn't be. - sp_repr_get_double(obj->getRepr(), "units_per_em", &units_per_em); + sp_repr_get_double(obj->getRepr(), "units-per-em", &units_per_em); } } -- cgit v1.2.3 From f7724473cc5e15c9b9d0e7c2fe362ebedaa69f55 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Tue, 5 Jul 2016 13:39:43 +0530 Subject: Fix deletion and selection of objects clicking on styledialog rows and vice-versa (bzr r14949.1.39) --- src/ui/dialog/styledialog.cpp | 159 ++++++++++++++++++++++++++++++------------ src/ui/dialog/styledialog.h | 12 ++-- 2 files changed, 122 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 406b984d7..b6e3d10ec 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -192,7 +192,8 @@ void StyleDialog::_addSelector() * class attribute for the selected object is set too. */ SPObject *obj; - SPObject *selectorObj; + std::vector objVec; + bool objExists = false; if (!_desktop->getSelection()->list().empty()) { std::vector selected = _desktop->getSelection()->list(); @@ -244,8 +245,8 @@ void StyleDialog::_addSelector() _row[_mColumns._selectorLabel] = _selectorName; _row[_mColumns._colAddRemove] = true; if (objExists) { - _row[_mColumns._colObj] = obj; - selectorObj = obj; + _row[_mColumns._colObj] = _desktop->selection->list(); + objVec = _row[_mColumns._colObj]; } break; default: @@ -257,7 +258,7 @@ void StyleDialog::_addSelector() * from selectorValue above. If style element already exists, then * the new selector's content is appended to its previous content. */ - _selectorVec.push_back(std::make_pair(std::make_pair(_selectorName, selectorObj), + _selectorVec.push_back(std::make_pair(std::make_pair(_selectorName, objVec), _selectorValue)); if (_styleElementNode()) { @@ -320,19 +321,14 @@ void StyleDialog::_delSelector() _selectorVec.erase(_selectorVec.begin()+i); } else { - std::stringstream str; std::string sel, key, value; - int index; - for (unsigned it = 0; it < _selectorVec.size(); ++it) { - str << _selectorVec[it].second; - index = it; - } - - while (std::getline(str, sel, '\n')) { + sel = _selectorVec[it].second; REMOVE_SPACES(sel); + std::cout << "sel" << sel << std::endl; if (!sel.empty()) { key = strtok(strdup(sel.c_str()), "{"); + REMOVE_SPACES(key); char *temp = strtok(NULL, "}"); if (strtok(temp, "}") != NULL) { value = strtok(temp, "}"); @@ -343,7 +339,7 @@ void StyleDialog::_delSelector() else { sel = sel; } - _selectorVec[index].second = sel; + _selectorVec[it].second = sel; } } } @@ -376,7 +372,7 @@ Inkscape::XML::Node* StyleDialog::_styleElementNode() { for (unsigned i = 0; i < _num; ++i) { if (std::string(_document->getReprRoot()->nthChild(i)->name()) - == "svg:style") { + == "svg:style") { _styleExists = true; _newDrawing = true; return _document->getReprRoot()->nthChild(i); @@ -409,9 +405,9 @@ std::string StyleDialog::_setClassAttribute(std::vector sel) * element. _newDrawing is flag is set to false check if an existing drawing is * opened. */ -std::vector, std::string> > StyleDialog::_getSelectorVec() +std::vector<_selectorVecType> StyleDialog::_getSelectorVec() { - std::string key, value; + std::string key, value, selId; for (unsigned i = 0; i < _num; ++i) { if (std::string(_document->getReprRoot()->nthChild(i)->name()) == "svg:style") { _styleExists = true; @@ -426,19 +422,74 @@ std::vector, std::string> > StyleDi * value is set to empty so that its corresponding XML repr is added. */ while(std::getline(str, sel, '\n')) { + std::vectorobjVec; REMOVE_SPACES(sel); if (!sel.empty()) { key = strtok(strdup(sel.c_str()), "{"); + _selectorName = key; char *temp = strtok(NULL, "}"); if (strtok(temp, "}") != NULL) { value = strtok(temp, "}"); } - std::string selId = key.erase(0, key.find_first_not_of('#')); - REMOVE_SPACES(selId); - REMOVE_SPACES(key); - SPObject *obj = _document->getObjectById(selId); - _selectorVec.push_back(std::make_pair(std::make_pair(key, obj), - sel)); + + std::stringstream ss(key); + std::string token; + std::size_t found = key.find(","); + if (found!=std::string::npos) { + while(std::getline(ss, token, ',')) { + REMOVE_SPACES(token); + + if (strcmp(token.substr(0,1).c_str(), ".") == 0) { + token.erase(0, token.find_first_not_of('.')); + for (unsigned i = 0; i < _num; ++i) { + if (_document->getReprRoot()-> + nthChild(i)->attribute("class") && + _document->getReprRoot()->nthChild(i) + ->attribute("class") == token) { + selId = _document->getReprRoot()->nthChild(i) + ->attribute("id"); + objVec.push_back( _document->getObjectById(selId)); + } + } + } + else if (strcmp(token.substr(0,1).c_str(), "#") == 0) { + token.erase(0, token.find_first_not_of('#')); + selId = token; + objVec.push_back(_document->getObjectById(selId)); + } + else { + std::cout << "simple text" << std::endl; + } + } + } + else { + REMOVE_SPACES(key); + std::string tkn = key; + if (strcmp(tkn.substr(0,1).c_str(), ".") == 0) { + tkn.erase(0, tkn.find_first_not_of('.')); + for (unsigned i = 0; i < _num; ++i) { + if (_document->getReprRoot()-> + nthChild(i)->attribute("class") && + _document->getReprRoot()->nthChild(i) + ->attribute("class") == tkn) { + selId = _document->getReprRoot()->nthChild(i) + ->attribute("id"); + objVec.push_back(_document->getObjectById(selId)); + } + } + } + else if (strcmp(tkn.substr(0,1).c_str(), "#") == 0) { + tkn.erase(0, key.find_first_not_of('#')); + selId = tkn; + objVec.push_back(_document->getObjectById(selId)); + } + else { + std::cout << "simple text" << std::endl; + } + } + _selectorValue = _selectorName + "{" + value + "}\n"; + _selectorVec.push_back(std::make_pair(std::make_pair(key, objVec), + _selectorValue)); } } } @@ -452,8 +503,7 @@ std::vector, std::string> > StyleDi * This function populates the treeview with selectors available in the * stylesheet. */ -std::string StyleDialog::_populateTree(std::vector, std::string> > _selVec) +std::string StyleDialog::_populateTree(std::vector<_selectorVecType> _selVec) { _selectorVec = _selVec; std::string selectorValue; @@ -463,7 +513,6 @@ std::string StyleDialog::_populateTree(std::vectorget_path(iter); - childrow = *(_store->append(row->children())); - childrow[_mColumns._selectorLabel] = obj->getId(); - childrow[_mColumns._colAddRemove] = false; - childrow[_mColumns._colObj] = obj; - Gtk::TreeModel::Children children = row.children(); + int i = atoi(path.to_string().c_str()); + Gtk::TreeModel::Row row = *iter; std::string childStyle; - if (children) { - for(Gtk::TreeModel::Children::iterator it = children.begin(); - it != children.end(); ++it) { - Gtk::TreeModel::Row row = *it; - SPObject *obj = row[_mColumns._colObj]; + + if (_selectorVec.size() != 0) { + if (!row.parent()) { + Gtk::TreeModel::Row childrow; + childrow = *(_store->append(row->children())); + std::cout << "_store->children() " << _store->children() + ->children().size() << std::endl; + + childrow[_mColumns._selectorLabel] = obj->getId(); + childrow[_mColumns._colAddRemove] = false; + childrow[_mColumns._colObj] = _desktop->selection->list(); childStyle = "#" + std::string(obj->getId()) + "{" + std::string(obj->getAttribute("style")) + "}\n"; } } + _selectorVec.push_back(std::make_pair(std::make_pair - (obj->getId(), obj), + (obj->getId(), + sel), childStyle)); } if (_styleElementNode()) { @@ -557,8 +609,9 @@ void StyleDialog::_selectedRowCallback(const Gtk::TreeModel::Path& path, if (iter) { Gtk::TreeModel::Row row = *iter; Gtk::TreeModel::Children children = row.children(); - if (row[_mColumns._colObj]) { - SPObject *obj = row[_mColumns._colObj]; + std::vector objVec = row[_mColumns._colObj]; + for (unsigned i = 0; i < objVec.size(); ++i) { + SPObject *obj = objVec[i]; _desktop->selection->add(obj); } if (children) { @@ -579,8 +632,9 @@ void StyleDialog::_checkAllChildren(Gtk::TreeModel::Children& children) for (Gtk::TreeModel::Children::iterator iter = children.begin(); iter!= children.end(); ++iter) { Gtk::TreeModel::Row childrow = *iter; - if (childrow[_mColumns._colObj]) { - SPObject *obj = childrow[_mColumns._colObj]; + std::vector objVec = childrow[_mColumns._colObj]; + for (unsigned i = 0; i < objVec.size(); ++i) { + SPObject *obj = objVec[i]; _desktop->selection->add(obj); } } @@ -604,8 +658,25 @@ void StyleDialog::_selectRow(Selection */*sel*/) for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) { Gtk::TreeModel::Row row = *iter; - if (obj == row[_mColumns._colObj]) { - _treeView.get_selection()->select(row); + std::vector objVec = row[_mColumns._colObj]; + std::vector childObjVec; + Gtk::TreeModel::Row childRow; + if (row.children()) { + for(Gtk::TreeModel::Children::iterator it = row.children().begin(); + it != row.children().end(); ++it) { + childRow = *it; + childObjVec = childRow[_mColumns._colObj]; + } + } + for (unsigned i = 0; i < objVec.size(); ++i) { + if (obj->getId() == objVec[i]->getId()) { + _treeView.get_selection()->select(row); + } + } + for (unsigned j = 0; j < childObjVec.size(); ++j) { + if (obj->getId() == childObjVec[j]->getId()) { + _treeView.get_selection()->select(childRow); + } } } } diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index 6e1ffbb2c..e47fbc96d 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -30,6 +30,8 @@ namespace Dialog { * @brief The StyleDialog class * A list of CSS selectors will show up in this dialog. */ +typedef std::pair >, std::string> +_selectorVecType; class StyleDialog : public UI::Widget::Panel { @@ -43,10 +45,10 @@ public: private: void _styleButton( Gtk::Button& btn, char const* iconName, char const* tooltip); std::string _setClassAttribute(std::vector); - std::vector, std::string> >_selectorVec; - std::vector, std::string> > _getSelectorVec(); - std::string _populateTree(std::vector, - std::string> >); + + std::vector<_selectorVecType>_selectorVec; + std::vector<_selectorVecType> _getSelectorVec(); + std::string _populateTree(std::vector<_selectorVecType>); bool _handleButtonEvent(GdkEventButton *event); void _selectedRowCallback(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* /* column */); @@ -62,7 +64,7 @@ private: { add(_selectorLabel); add(_colAddRemove); add(_colObj); } Gtk::TreeModelColumn _selectorLabel; Gtk::TreeModelColumn _colAddRemove; - Gtk::TreeModelColumn _colObj; + Gtk::TreeModelColumn > _colObj; }; SPDesktop* _desktop; -- cgit v1.2.3 From 7c612210cbeecef13c9148a3e35a5f73dd5a6347 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Wed, 6 Jul 2016 14:38:04 +0530 Subject: Fix issues related to updating style content and selection of rows in treeview (bzr r14949.1.40) --- src/ui/dialog/styledialog.cpp | 62 ++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index b6e3d10ec..72fea5dc6 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -200,23 +200,16 @@ void StyleDialog::_addSelector() for (unsigned i = 0; i < selected.size(); ++i) { obj = selected.at(i); objExists = true; - std::string style; - - if (obj->getRepr()->attribute("style")) { - for (List iter = obj->getRepr()->attributeList(); - iter; ++iter) { - gchar const * property = g_quark_to_string(iter->key); - gchar const * value = iter->value; + if (!obj->getRepr()->attribute("style")) { + obj->getRepr()->setAttribute("style", NULL); + } - if (std::string(property) == "style") { - _selectorValue = _selectorName + "{" - + std::string(value) + "}" + "\n"; - } - } + if (obj->getAttribute("style") == NULL) { + _selectorValue = _selectorName + "{" + "}" + "\n"; } else { - style = " "; - obj->getRepr()->setAttribute("style", style); + _selectorValue = _selectorName + "{" + + obj->getAttribute("style") + "}" + "\n"; } if (strcmp(_selectorName.substr(0,1).c_str(), ".") == 0) { @@ -647,13 +640,20 @@ void StyleDialog::_checkAllChildren(Gtk::TreeModel::Children& children) */ void StyleDialog::_selectRow(Selection */*sel*/) { + SPObject *obj = NULL; + bool objExists = false; if (!_desktop->selection->list().empty()) { - SPObject *obj; std::vector selected = _desktop->getSelection()->list(); - for (unsigned i = 0; i < selected.size(); ++i) { - obj = selected.at(i); - } + obj = selected.back(); + } + /** + * If obj has some SPObject, then it is added to desktop's selection. If a + * row in treeview has children, those rows are checked too against selected + * object's id. If an object which is not present in any selector is selected, + * the treeview's selections are unselected. + */ + if (obj != NULL) { Gtk::TreeModel::Children children = _store->children(); for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) { @@ -661,24 +661,32 @@ void StyleDialog::_selectRow(Selection */*sel*/) std::vector objVec = row[_mColumns._colObj]; std::vector childObjVec; Gtk::TreeModel::Row childRow; + + for (unsigned i = 0; i < objVec.size(); ++i) { + if (obj->getId() == objVec[i]->getId()) { + _treeView.get_selection()->select(row); + objExists = true; + } + } + if (row.children()) { for(Gtk::TreeModel::Children::iterator it = row.children().begin(); it != row.children().end(); ++it) { childRow = *it; childObjVec = childRow[_mColumns._colObj]; } - } - for (unsigned i = 0; i < objVec.size(); ++i) { - if (obj->getId() == objVec[i]->getId()) { - _treeView.get_selection()->select(row); - } - } - for (unsigned j = 0; j < childObjVec.size(); ++j) { - if (obj->getId() == childObjVec[j]->getId()) { - _treeView.get_selection()->select(childRow); + for (unsigned j = 0; j < childObjVec.size(); ++j) { + if (obj->getId() == childObjVec[j]->getId()) { + _treeView.get_selection()->select(childRow); + objExists = true; + } } } } + + if (!objExists) { + _treeView.get_selection()->unselect_all(); + } } } -- cgit v1.2.3 From 7b0f2601a652adb7566bfac6ec0eab7a9d95c7a2 Mon Sep 17 00:00:00 2001 From: Sebastian Faubel Date: Wed, 6 Jul 2016 17:42:00 +0200 Subject: Fixing build for Linux. Replaced tabs with whitespaces. (bzr r15002.1.7) --- src/CMakeLists.txt | 883 +++++++++++++++++++++++++++-------------------------- 1 file changed, 447 insertions(+), 436 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d979d7c13..d4ba9b1f0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,420 +3,420 @@ # ----------------------------------------------------------------------------- set(sp_SRC - attribute-rel-css.cpp - attribute-rel-svg.cpp - attribute-rel-util.cpp - attribute-sort-util.cpp - sp-anchor.cpp - sp-clippath.cpp - sp-conn-end-pair.cpp - sp-conn-end.cpp - sp-cursor.cpp - sp-defs.cpp - sp-desc.cpp - sp-ellipse.cpp - sp-factory.cpp - sp-filter-primitive.cpp - sp-filter-reference.cpp - sp-filter.cpp - sp-flowdiv.cpp - sp-flowregion.cpp - sp-flowtext.cpp - sp-font-face.cpp - sp-font.cpp - sp-glyph-kerning.cpp - sp-glyph.cpp - sp-gradient-reference.cpp - sp-gradient.cpp - sp-guide.cpp - sp-hatch-path.cpp - sp-hatch.cpp - sp-image.cpp - sp-item-group.cpp - sp-item-notify-moveto.cpp - sp-item-rm-unsatisfied-cns.cpp - sp-item-transform.cpp - sp-item-update-cns.cpp - sp-item.cpp - sp-line.cpp - sp-linear-gradient.cpp - sp-lpe-item.cpp - sp-marker.cpp - sp-mask.cpp - sp-mesh-array.cpp - sp-mesh-patch.cpp - sp-mesh-row.cpp - sp-mesh.cpp - sp-metadata.cpp - sp-missing-glyph.cpp - sp-namedview.cpp - sp-object-group.cpp - sp-object.cpp - sp-offset.cpp - sp-paint-server.cpp - sp-path.cpp - sp-pattern.cpp - sp-polygon.cpp - sp-polyline.cpp - sp-radial-gradient.cpp - sp-rect.cpp - sp-root.cpp - sp-script.cpp - sp-shape.cpp - sp-solid-color.cpp - sp-spiral.cpp - sp-star.cpp - sp-stop.cpp - sp-string.cpp - sp-style-elem.cpp - sp-switch.cpp - sp-symbol.cpp - sp-tag-use-reference.cpp - sp-tag-use.cpp - sp-tag.cpp - sp-text.cpp - sp-title.cpp - sp-tref-reference.cpp - sp-tref.cpp - sp-tspan.cpp - sp-use-reference.cpp - sp-use.cpp - splivarot.cpp - viewbox.cpp + attribute-rel-css.cpp + attribute-rel-svg.cpp + attribute-rel-util.cpp + attribute-sort-util.cpp + sp-anchor.cpp + sp-clippath.cpp + sp-conn-end-pair.cpp + sp-conn-end.cpp + sp-cursor.cpp + sp-defs.cpp + sp-desc.cpp + sp-ellipse.cpp + sp-factory.cpp + sp-filter-primitive.cpp + sp-filter-reference.cpp + sp-filter.cpp + sp-flowdiv.cpp + sp-flowregion.cpp + sp-flowtext.cpp + sp-font-face.cpp + sp-font.cpp + sp-glyph-kerning.cpp + sp-glyph.cpp + sp-gradient-reference.cpp + sp-gradient.cpp + sp-guide.cpp + sp-hatch-path.cpp + sp-hatch.cpp + sp-image.cpp + sp-item-group.cpp + sp-item-notify-moveto.cpp + sp-item-rm-unsatisfied-cns.cpp + sp-item-transform.cpp + sp-item-update-cns.cpp + sp-item.cpp + sp-line.cpp + sp-linear-gradient.cpp + sp-lpe-item.cpp + sp-marker.cpp + sp-mask.cpp + sp-mesh-array.cpp + sp-mesh-patch.cpp + sp-mesh-row.cpp + sp-mesh.cpp + sp-metadata.cpp + sp-missing-glyph.cpp + sp-namedview.cpp + sp-object-group.cpp + sp-object.cpp + sp-offset.cpp + sp-paint-server.cpp + sp-path.cpp + sp-pattern.cpp + sp-polygon.cpp + sp-polyline.cpp + sp-radial-gradient.cpp + sp-rect.cpp + sp-root.cpp + sp-script.cpp + sp-shape.cpp + sp-solid-color.cpp + sp-spiral.cpp + sp-star.cpp + sp-stop.cpp + sp-string.cpp + sp-style-elem.cpp + sp-switch.cpp + sp-symbol.cpp + sp-tag-use-reference.cpp + sp-tag-use.cpp + sp-tag.cpp + sp-text.cpp + sp-title.cpp + sp-tref-reference.cpp + sp-tref.cpp + sp-tspan.cpp + sp-use-reference.cpp + sp-use.cpp + splivarot.cpp + viewbox.cpp - # ------- - # Headers - attribute-rel-css.h - attribute-rel-svg.h - attribute-rel-util.h - attribute-sort-util.h - sp-anchor.h - sp-clippath.h - sp-conn-end-pair.h - sp-conn-end.h - sp-cursor.h - sp-defs.h - sp-desc.h - sp-ellipse.h - sp-factory.h - sp-filter-primitive.h - sp-filter-reference.h - sp-filter-units.h - sp-filter.h - sp-flowdiv.h - sp-flowregion.h - sp-flowtext.h - sp-font-face.h - sp-font.h - sp-glyph-kerning.h - sp-glyph.h - sp-gradient-reference.h - sp-gradient-spread.h - sp-gradient-test.h - sp-gradient-units.h - sp-gradient-vector.h - sp-gradient.h - sp-guide-attachment.h - sp-guide-constraint.h - sp-guide.h - sp-hatch-path.h - sp-hatch.h - sp-image.h - sp-item-group.h - sp-item-notify-moveto.h - sp-item-rm-unsatisfied-cns.h - sp-item-transform.h - sp-item-update-cns.h - sp-item.h - sp-line.h - sp-linear-gradient.h - sp-lpe-item.h - sp-marker-loc.h - sp-marker.h - sp-mask.h - sp-mesh-array.h - sp-mesh-patch.h - sp-mesh-row.h - sp-mesh.h - sp-metadata.h - sp-missing-glyph.h - sp-namedview.h - sp-object-group.h - sp-object.h - sp-offset.h - sp-paint-server-reference.h - sp-paint-server.h - sp-path.h - sp-pattern.h - sp-polygon.h - sp-polyline.h - sp-radial-gradient.h - sp-rect.h - sp-root.h - sp-script.h - sp-shape.h - sp-solid-color.h - sp-spiral.h - sp-star.h - sp-stop.h - sp-string.h - sp-style-elem-test.h - sp-style-elem.h - sp-switch.h - sp-symbol.h - sp-tag.h - sp-tag-use.h - sp-tag-use-reference.h - sp-text.h - sp-textpath.h - sp-title.h - sp-tref-reference.h - sp-tref.h - sp-tspan.h - sp-use-reference.h - sp-use.h - viewbox.h + # ------- + # Headers + attribute-rel-css.h + attribute-rel-svg.h + attribute-rel-util.h + attribute-sort-util.h + sp-anchor.h + sp-clippath.h + sp-conn-end-pair.h + sp-conn-end.h + sp-cursor.h + sp-defs.h + sp-desc.h + sp-ellipse.h + sp-factory.h + sp-filter-primitive.h + sp-filter-reference.h + sp-filter-units.h + sp-filter.h + sp-flowdiv.h + sp-flowregion.h + sp-flowtext.h + sp-font-face.h + sp-font.h + sp-glyph-kerning.h + sp-glyph.h + sp-gradient-reference.h + sp-gradient-spread.h + sp-gradient-test.h + sp-gradient-units.h + sp-gradient-vector.h + sp-gradient.h + sp-guide-attachment.h + sp-guide-constraint.h + sp-guide.h + sp-hatch-path.h + sp-hatch.h + sp-image.h + sp-item-group.h + sp-item-notify-moveto.h + sp-item-rm-unsatisfied-cns.h + sp-item-transform.h + sp-item-update-cns.h + sp-item.h + sp-line.h + sp-linear-gradient.h + sp-lpe-item.h + sp-marker-loc.h + sp-marker.h + sp-mask.h + sp-mesh-array.h + sp-mesh-patch.h + sp-mesh-row.h + sp-mesh.h + sp-metadata.h + sp-missing-glyph.h + sp-namedview.h + sp-object-group.h + sp-object.h + sp-offset.h + sp-paint-server-reference.h + sp-paint-server.h + sp-path.h + sp-pattern.h + sp-polygon.h + sp-polyline.h + sp-radial-gradient.h + sp-rect.h + sp-root.h + sp-script.h + sp-shape.h + sp-solid-color.h + sp-spiral.h + sp-star.h + sp-stop.h + sp-string.h + sp-style-elem-test.h + sp-style-elem.h + sp-switch.h + sp-symbol.h + sp-tag.h + sp-tag-use.h + sp-tag-use-reference.h + sp-text.h + sp-textpath.h + sp-title.h + sp-tref-reference.h + sp-tref.h + sp-tspan.h + sp-use-reference.h + sp-use.h + viewbox.h ) set(inkscape_SRC - attributes.cpp - axis-manip.cpp - box3d-side.cpp - box3d.cpp - color-profile.cpp - color.cpp - composite-undo-stack-observer.cpp - conditions.cpp - conn-avoid-ref.cpp - console-output-undo-observer.cpp - context-fns.cpp - desktop-events.cpp - desktop-style.cpp - desktop.cpp - device-manager.cpp - dir-util.cpp - document-subset.cpp - document-undo.cpp - document.cpp - ege-color-prof-tracker.cpp - event-log.cpp - extract-uri.cpp - file.cpp - filter-chemistry.cpp - filter-enums.cpp - gc-anchored.cpp - gc-finalized.cpp - gradient-chemistry.cpp - gradient-drag.cpp - graphlayout.cpp - guide-snapper.cpp - help.cpp - id-clash.cpp - inkscape.cpp - knot-holder-entity.cpp - knot-ptr.cpp - knot.cpp - knotholder.cpp - layer-fns.cpp - layer-manager.cpp - layer-model.cpp - line-geometry.cpp - line-snapper.cpp - main-cmdlineact.cpp - media.cpp - message-context.cpp - message-stack.cpp - mod360.cpp - object-hierarchy.cpp - object-snapper.cpp - path-chemistry.cpp - persp3d-reference.cpp - persp3d.cpp - perspective-line.cpp - preferences.cpp - prefix.cpp - print.cpp - profile-manager.cpp - proj_pt.cpp - pure-transform.cpp - rdf.cpp - removeoverlap.cpp - resource-manager.cpp - rubberband.cpp - satisfied-guide-cns.cpp - selcue.cpp - selection-chemistry.cpp - selection-describer.cpp - selection.cpp - seltrans-handles.cpp - seltrans.cpp - shortcuts.cpp - snap-preferences.cpp - snap.cpp - snapped-curve.cpp - snapped-line.cpp - snapped-point.cpp - snapper.cpp - style-internal.cpp - style.cpp - svg-view-widget.cpp - svg-view.cpp - text-chemistry.cpp - text-editing.cpp - transf_mat_3x4.cpp - unclump.cpp - unicoderange.cpp - uri-references.cpp - uri.cpp - vanishing-point.cpp - verbs.cpp - version.cpp + attributes.cpp + axis-manip.cpp + box3d-side.cpp + box3d.cpp + color-profile.cpp + color.cpp + composite-undo-stack-observer.cpp + conditions.cpp + conn-avoid-ref.cpp + console-output-undo-observer.cpp + context-fns.cpp + desktop-events.cpp + desktop-style.cpp + desktop.cpp + device-manager.cpp + dir-util.cpp + document-subset.cpp + document-undo.cpp + document.cpp + ege-color-prof-tracker.cpp + event-log.cpp + extract-uri.cpp + file.cpp + filter-chemistry.cpp + filter-enums.cpp + gc-anchored.cpp + gc-finalized.cpp + gradient-chemistry.cpp + gradient-drag.cpp + graphlayout.cpp + guide-snapper.cpp + help.cpp + id-clash.cpp + inkscape.cpp + knot-holder-entity.cpp + knot-ptr.cpp + knot.cpp + knotholder.cpp + layer-fns.cpp + layer-manager.cpp + layer-model.cpp + line-geometry.cpp + line-snapper.cpp + main-cmdlineact.cpp + media.cpp + message-context.cpp + message-stack.cpp + mod360.cpp + object-hierarchy.cpp + object-snapper.cpp + path-chemistry.cpp + persp3d-reference.cpp + persp3d.cpp + perspective-line.cpp + preferences.cpp + prefix.cpp + print.cpp + profile-manager.cpp + proj_pt.cpp + pure-transform.cpp + rdf.cpp + removeoverlap.cpp + resource-manager.cpp + rubberband.cpp + satisfied-guide-cns.cpp + selcue.cpp + selection-chemistry.cpp + selection-describer.cpp + selection.cpp + seltrans-handles.cpp + seltrans.cpp + shortcuts.cpp + snap-preferences.cpp + snap.cpp + snapped-curve.cpp + snapped-line.cpp + snapped-point.cpp + snapper.cpp + style-internal.cpp + style.cpp + svg-view-widget.cpp + svg-view.cpp + text-chemistry.cpp + text-editing.cpp + transf_mat_3x4.cpp + unclump.cpp + unicoderange.cpp + uri-references.cpp + uri.cpp + vanishing-point.cpp + verbs.cpp + version.cpp - # ------- - # Headers - MultiPrinter.h - PylogFormatter.h - TRPIFormatter.h - attributes-test.h - attributes.h - axis-manip.h - bad-uri-exception.h - box3d-side.h - box3d.h - cms-color-types.h - cms-system.h - color-profile-cms-fns.h - color-profile-test.h - color-profile.h - color-rgba.h - color.h - colorspace.h - composite-undo-stack-observer.h - conditions.h - conn-avoid-ref.h - console-output-undo-observer.h - context-fns.h - decimal-round.h - desktop-events.h - desktop-style.h - desktop.h - device-manager.h - dir-util-test.h - dir-util.h - document-private.h - document-subset.h - document-undo.h - document.h - ege-color-prof-tracker.h - enums.h - event-log.h - event.h - extract-uri-test.h - extract-uri.h - file.h - fill-or-stroke.h - filter-chemistry.h - filter-enums.h - gc-anchored.h - gc-finalized.h - gradient-chemistry.h - gradient-drag.h - graphlayout.h - guide-snapper.h - help.h - helper-fns.h - icon-size.h - id-clash.h - inkscape-version.h - inkscape.h - isinf.h - knot-enums.h - knot-holder-entity.h - knot-ptr.h - knot.h - knotholder.h - layer-fns.h - layer-manager.h - layer-model.h - line-geometry.h - line-snapper.h - macros.h - main-cmdlineact.h - marker-test.h - media.h - menus-skeleton.h - message-context.h - message-stack.h - message.h - mod360-test.h - mod360.h - number-opt-number.h - object-hierarchy.h - object-snapper.h - object-test.h - path-chemistry.h - path-prefix.h - persp3d-reference.h - persp3d.h - perspective-line.h - preferences-skeleton.h - preferences-test.h - preferences.h - prefix.h - print.h - profile-manager.h - proj_pt.h - pure-transform.h - rdf.h - remove-last.h - removeoverlap.h - require-config.h - resource-manager.h - round-test.h - round.h - rubberband.h - satisfied-guide-cns.h - selcue.h - selection-chemistry.h - selection-describer.h - selection.h - seltrans-handles.h - seltrans.h - shortcuts.h - snap-candidate.h - snap-enums.h - snap-preferences.h - snap.h - snapped-curve.h - snapped-line.h - snapped-point.h - snapper.h - splivarot.h - streq.h - strneq.h - style-enums.h - style-internal.h - style-test.h - style.h - svg-profile.h - svg-view-widget.h - svg-view.h - syseq.h - test-helpers.h - text-chemistry.h - text-editing.h - text-tag-attributes.h - transf_mat_3x4.h - unclump.h - undo-stack-observer.h - unicoderange.h - uri-references.h - uri-test.h - uri.h - vanishing-point.h - verbs-test.h - verbs.h - version.h + # ------- + # Headers + MultiPrinter.h + PylogFormatter.h + TRPIFormatter.h + attributes-test.h + attributes.h + axis-manip.h + bad-uri-exception.h + box3d-side.h + box3d.h + cms-color-types.h + cms-system.h + color-profile-cms-fns.h + color-profile-test.h + color-profile.h + color-rgba.h + color.h + colorspace.h + composite-undo-stack-observer.h + conditions.h + conn-avoid-ref.h + console-output-undo-observer.h + context-fns.h + decimal-round.h + desktop-events.h + desktop-style.h + desktop.h + device-manager.h + dir-util-test.h + dir-util.h + document-private.h + document-subset.h + document-undo.h + document.h + ege-color-prof-tracker.h + enums.h + event-log.h + event.h + extract-uri-test.h + extract-uri.h + file.h + fill-or-stroke.h + filter-chemistry.h + filter-enums.h + gc-anchored.h + gc-finalized.h + gradient-chemistry.h + gradient-drag.h + graphlayout.h + guide-snapper.h + help.h + helper-fns.h + icon-size.h + id-clash.h + inkscape-version.h + inkscape.h + isinf.h + knot-enums.h + knot-holder-entity.h + knot-ptr.h + knot.h + knotholder.h + layer-fns.h + layer-manager.h + layer-model.h + line-geometry.h + line-snapper.h + macros.h + main-cmdlineact.h + marker-test.h + media.h + menus-skeleton.h + message-context.h + message-stack.h + message.h + mod360-test.h + mod360.h + number-opt-number.h + object-hierarchy.h + object-snapper.h + object-test.h + path-chemistry.h + path-prefix.h + persp3d-reference.h + persp3d.h + perspective-line.h + preferences-skeleton.h + preferences-test.h + preferences.h + prefix.h + print.h + profile-manager.h + proj_pt.h + pure-transform.h + rdf.h + remove-last.h + removeoverlap.h + require-config.h + resource-manager.h + round-test.h + round.h + rubberband.h + satisfied-guide-cns.h + selcue.h + selection-chemistry.h + selection-describer.h + selection.h + seltrans-handles.h + seltrans.h + shortcuts.h + snap-candidate.h + snap-enums.h + snap-preferences.h + snap.h + snapped-curve.h + snapped-line.h + snapped-point.h + snapper.h + splivarot.h + streq.h + strneq.h + style-enums.h + style-internal.h + style-test.h + style.h + svg-profile.h + svg-view-widget.h + svg-view.h + syseq.h + test-helpers.h + text-chemistry.h + text-editing.h + text-tag-attributes.h + transf_mat_3x4.h + unclump.h + undo-stack-observer.h + unicoderange.h + uri-references.h + uri-test.h + uri.h + vanishing-point.h + verbs-test.h + verbs.h + version.h ) # ----------------------------------------------------------------------------- @@ -425,19 +425,19 @@ set(inkscape_SRC # a custom target that is always built add_custom_target( - inkscape_version ALL - COMMAND ${CMAKE_COMMAND} - -DINKSCAPE_SOURCE_DIR=${CMAKE_SOURCE_DIR} - -DINKSCAPE_BINARY_DIR=${CMAKE_BINARY_DIR} - -P ${CMAKE_SOURCE_DIR}/CMakeScripts/inkscape-version.cmake) + inkscape_version ALL + COMMAND ${CMAKE_COMMAND} + -DINKSCAPE_SOURCE_DIR=${CMAKE_SOURCE_DIR} + -DINKSCAPE_BINARY_DIR=${CMAKE_BINARY_DIR} + -P ${CMAKE_SOURCE_DIR}/CMakeScripts/inkscape-version.cmake) # buildinfo.h is a generated file set_source_files_properties( - ${CMAKE_BINARY_DIR}/src/inkscape-version.cpp - PROPERTIES GENERATED TRUE) + ${CMAKE_BINARY_DIR}/src/inkscape-version.cpp + PROPERTIES GENERATED TRUE) list(APPEND inkscape_SRC - ${CMAKE_BINARY_DIR}/src/inkscape-version.cpp + ${CMAKE_BINARY_DIR}/src/inkscape-version.cpp ) @@ -477,8 +477,8 @@ add_subdirectory(libdepixelize) get_property(inkscape_global_SRC GLOBAL PROPERTY inkscape_global_SRC) set(inkscape_SRC - ${inkscape_global_SRC} - ${inkscape_SRC} + ${inkscape_global_SRC} + ${inkscape_SRC} ) # ----------------------------------------------------------------------------- @@ -488,23 +488,23 @@ set(inkscape_SRC #add_inkscape_lib(inkscape_LIB "${inkscape_SRC}") if(WIN32) - # Sources for the inkscape executable on Windows. - set(main_SRC - registrytool.h - registrytool.cpp - main.cpp - winmain.cpp - #winconsole.cpp - ) - - # Add the platform specific resource files (enabling the app icon). - if(${HAVE_MINGW64}) - list(APPEND main_SRC inkscape-x64.rc) - else() - list(APPEND main_SRC inkscape.rc) - endif() + # Sources for the inkscape executable on Windows. + set(main_SRC + registrytool.h + registrytool.cpp + main.cpp + winmain.cpp + #winconsole.cpp + ) + + # Add the platform specific resource files (enabling the app icon). + if(${HAVE_MINGW64}) + list(APPEND main_SRC inkscape-x64.rc) + else() + list(APPEND main_SRC inkscape.rc) + endif() else() - set(main_SRC main.cpp) + set(main_SRC main.cpp) endif() # Build everything except main and inkview.c in a shared library. @@ -550,4 +550,15 @@ target_link_libraries(inkscape_base ${INKSCAPE_TARGET_LIBS}) # Link inkscape and inkview against inkscape_base target_link_libraries(inkscape inkscape_base) -target_link_libraries(inkview inkscape_base) \ No newline at end of file +target_link_libraries(inkview inkscape_base) + +if(NOT WIN32) + #Define the installation + install(TARGETS + inkscape_base + inkscape + inkview + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib/inkscape + ARCHIVE DESTINATION lib/inkscape) +endif() -- cgit v1.2.3 From 71cb7d8ddbabf102501c9b245c2eea99a4ba1011 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Fri, 8 Jul 2016 09:17:55 +0200 Subject: Documentation. French documentation translation updated. (bzr r15013) --- src/ui/dialog/aboutbox.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/aboutbox.cpp b/src/ui/dialog/aboutbox.cpp index 1a87a9718..6276d3391 100644 --- a/src/ui/dialog/aboutbox.cpp +++ b/src/ui/dialog/aboutbox.cpp @@ -467,7 +467,8 @@ void AboutBox::initStrings() { "Adib Taraben , 2004-2014.\n" "Alan Monfort , 2009-2010.\n" "Alastair McKinstry , 2000.\n" -"Aleksandar UroÅ¡ević , 2004-2006.\n" +"Aleksandar Marković , 2015.\n" +"Aleksandar UroÅ¡ević , 2004-2009.\n" "Alessio Frusciante , 2002, 2003.\n" "Alexander Shopov , 2006.\n" "Alexandre Prokoudine , 2005, 2010-2014.\n" @@ -499,18 +500,19 @@ void AboutBox::initStrings() { "Cédric Gemy , 2006.\n" "Daniel Díaz , 2004.\n" "Didier Conchaudron , 2003.\n" -"Dimitris Spingos , 2011-2013.\n" +"Dimitris Spingos (ΔημήτÏης Σπίγγος) , 2011-2015.\n" "Dorji Tashi , 2006.\n" "Duarte Loreto 2002, 2003 (Maintainer).\n" "Elias Norberg , 2009.\n" "Equipe de Tradução Inkscape Brasil , 2007.\n" "Fatih Demir , 2000.\n" -"Firas Hanife , 2014-2015.\n" +"Firas Hanife , 2014-2016.\n" "Foppe Benedictus , 2007-2009.\n" "Francesc Dorca , 2003. Traducció sodipodi.\n" "Francisco Javier F. Serrador , 2003.\n" "Francisco Xosé Vázquez Grandal , 2001.\n" "Frederic Rodrigo , 2004-2005.\n" +"Ganesh Murmu , 2014.\n" "Ge'ez Frontier Foundation , 2002.\n" "George Boukeas , 2011.\n" "Heiko Wöhrle , 2014.\n" @@ -528,6 +530,7 @@ void AboutBox::initStrings() { "Jeroen van der Vegt , 2003, 2005, 2008.\n" "Jin-Hwan Jeong , 2009.\n" "Jonathan Ernst , 2006.\n" +"Jordi Mas i Hernàndez , 2015.\n" "Jose Antonio Salgueiro Aquino , 2003.\n" "Josef Vybiral , 2005-2006.\n" "Juarez Rudsatz , 2004.\n" @@ -542,10 +545,11 @@ void AboutBox::initStrings() { "Kingsley Turner , 2006.\n" "Kitae , 2006.\n" "Kjartan Maraas , 2000-2002.\n" -"Kris De Gussem , 2008-2014.\n" +"Kris De Gussem , 2008-2015.\n" "Lauris Kaplinski , 2000.\n" "Leandro Regueiro , 2006-2008, 2010.\n" "Liu Xiaoqin , 2008.\n" +"Louni Kandulna , 2014.\n" "Luca Bruno , 2005.\n" "Lucas Vieites Fariña, 2003-2013.\n" "Mahesh subedi , 2006.\n" @@ -561,8 +565,10 @@ void AboutBox::initStrings() { "Mufit Eribol , 2000.\n" "Muhammad Bashir Al-Noimi , 2008.\n" "Myckel Habets , 2008.\n" +"Nasreen , 2013.\n" "Nguyen Dinh Trung , 2007, 2008.\n" -"Nicolas Dufour , 2008-2014.\n" +"Nicolas Dufour , 2008-2016.\n" +"Paresh prabhu , 2013.\n" "Pawan Chitrakar , 2006.\n" "PrzemysÅ‚aw Loesch , 2005.\n" "Quico Llach , 2000. Traducció sodipodi.\n" @@ -570,6 +576,8 @@ void AboutBox::initStrings() { "Riku Leino , 2006-2011.\n" "Rune Rønde Laursen , 2006.\n" "Ruud Steltenpool , 2006.\n" +"Sangeeta , 2011.\n" +"Savitha , 2013.\n" "Serdar Soytetir , 2005.\n" "shivaken , 2004.\n" "Shyam Krishna Bal , 2006.\n" @@ -577,8 +585,11 @@ void AboutBox::initStrings() { "Spyros Blanas , 2006, 2011.\n" "Stefan Graubner , 2005.\n" "Supranee Thirawatthanasuk , 2006.\n" +"Sushma Joshi , 2011.\n" +"Sveinn í Felli , 2014-2015.\n" +"Sylvain Chiron , 2016.\n" "Takeshi Aihana , 2000, 2001.\n" -"Tim Sheridan , 2007-2014.\n" +"Tim Sheridan , 2007-2016.\n" "Theppitak Karoonboonyanan , 2006.\n" "Thiago Pimentel , 2006.\n" "Toshifumi Sato , 2005.\n" @@ -592,6 +603,7 @@ void AboutBox::initStrings() { "Vital Khilko , 2003.\n" "Vitaly Lipatov , 2002, 2004.\n" "vonHalenbach , 2005.\n" +"vrundeshw , 2012.\n" "Waluyo Adi Siswanto , 2011.\n" "Wang Li , 2002.\n" "Wei-Lun Chao , 2006.\n" -- cgit v1.2.3 From 67f04a5e0e1bff0523a97d4aa16357849e51e1d8 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Fri, 8 Jul 2016 17:19:12 +0530 Subject: Selects matching objects for single as well as double click on selector (bzr r14949.1.42) --- src/ui/dialog/styledialog.cpp | 89 +++++++++++++++++++++++++++---------------- src/ui/dialog/styledialog.h | 4 +- 2 files changed, 59 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 72fea5dc6..7e0cb135f 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -113,9 +113,10 @@ StyleDialog::StyleDialog() : _handleButtonEvent), false); - _treeView.signal_row_activated().connect(sigc::mem_fun(*this, - &StyleDialog:: - _selectedRowCallback)); + _treeView.signal_button_press_event().connect_notify(sigc::mem_fun + (*this, &StyleDialog:: + _buttonEventsSelectObjs), + false); } StyleDialog::~StyleDialog() @@ -548,18 +549,14 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) if (iter) { path = _treeView.get_model()->get_path(iter); - int i = atoi(path.to_string().c_str()); Gtk::TreeModel::Row row = *iter; std::string childStyle; - if (_selectorVec.size() != 0) { if (!row.parent()) { Gtk::TreeModel::Row childrow; childrow = *(_store->append(row->children())); - std::cout << "_store->children() " << _store->children() - ->children().size() << std::endl; - - childrow[_mColumns._selectorLabel] = obj->getId(); + childrow[_mColumns._selectorLabel] = "#" + + std::string(obj->getId()); childrow[_mColumns._colAddRemove] = false; childrow[_mColumns._colObj] = _desktop->selection->list(); childStyle = "#" + std::string(obj->getId()) + "{" + @@ -588,27 +585,59 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) } /** - * @brief StyleDialog::_selected_row_callback - * @param path + * @brief StyleDialog::_selectObjects + * @param event + * This function detects single or double click on a selector in any row. Single + * click on a selector selects the matching objects. A double click on any + * selector selects the matching objects as well as will open CSS dialog. It + * calls _selectObjects to add objects to selection. + * TODO: Open CSS dialog on double click. + */ +void StyleDialog::_buttonEventsSelectObjs(GdkEventButton* event ) +{ + if (event->type == GDK_BUTTON_PRESS && event->button == 1) { + int x = static_cast(event->x); + int y = static_cast(event->y); + _selectObjects(x, y); + } + else if (event->type == GDK_2BUTTON_PRESS && event->button == 1) { + int x = static_cast(event->x); + int y = static_cast(event->y); + _selectObjects(x, y); + //Open CSS dialog here. + } +} + +/** + * @brief StyleDialog::_selectObjects + * @param eventX + * @param eventY * This function selects objects in the drawing corresponding to the selector * selected in the treeview. */ -void StyleDialog::_selectedRowCallback(const Gtk::TreeModel::Path& path, - Gtk::TreeViewColumn* column ) +void StyleDialog::_selectObjects(int eventX, int eventY) { _desktop->selection->clear(); - if (column == _treeView.get_column(1)) { - Gtk::TreeModel::iterator iter = _store->get_iter(path); - if (iter) { - Gtk::TreeModel::Row row = *iter; - Gtk::TreeModel::Children children = row.children(); - std::vector objVec = row[_mColumns._colObj]; - for (unsigned i = 0; i < objVec.size(); ++i) { - SPObject *obj = objVec[i]; - _desktop->selection->add(obj); - } - if (children) { - _checkAllChildren(children); + Gtk::TreeViewColumn *col = _treeView.get_column(1); + Gtk::TreeModel::Path path; + int x = eventX; + int y = eventY; + int x2 = 0; + int y2 = 0; + if (_treeView.get_path_at_pos(x, y, path, col, x2, y2)) { + if (col == _treeView.get_column(1)) { + Gtk::TreeModel::iterator iter = _store->get_iter(path); + if (iter) { + Gtk::TreeModel::Row row = *iter; + Gtk::TreeModel::Children children = row.children(); + std::vector objVec = row[_mColumns._colObj]; + for (unsigned i = 0; i < objVec.size(); ++i) { + SPObject *obj = objVec[i]; + _desktop->selection->add(obj); + } + if (children) { + _checkAllChildren(children); + } } } } @@ -641,7 +670,6 @@ void StyleDialog::_checkAllChildren(Gtk::TreeModel::Children& children) void StyleDialog::_selectRow(Selection */*sel*/) { SPObject *obj = NULL; - bool objExists = false; if (!_desktop->selection->list().empty()) { std::vector selected = _desktop->getSelection()->list(); obj = selected.back(); @@ -665,7 +693,6 @@ void StyleDialog::_selectRow(Selection */*sel*/) for (unsigned i = 0; i < objVec.size(); ++i) { if (obj->getId() == objVec[i]->getId()) { _treeView.get_selection()->select(row); - objExists = true; } } @@ -678,15 +705,13 @@ void StyleDialog::_selectRow(Selection */*sel*/) for (unsigned j = 0; j < childObjVec.size(); ++j) { if (obj->getId() == childObjVec[j]->getId()) { _treeView.get_selection()->select(childRow); - objExists = true; } } } } - - if (!objExists) { - _treeView.get_selection()->unselect_all(); - } + } + else { + _treeView.get_selection()->unselect_all(); } } diff --git a/src/ui/dialog/styledialog.h b/src/ui/dialog/styledialog.h index e47fbc96d..08061d923 100644 --- a/src/ui/dialog/styledialog.h +++ b/src/ui/dialog/styledialog.h @@ -50,8 +50,8 @@ private: std::vector<_selectorVecType> _getSelectorVec(); std::string _populateTree(std::vector<_selectorVecType>); bool _handleButtonEvent(GdkEventButton *event); - void _selectedRowCallback(const Gtk::TreeModel::Path& path, - Gtk::TreeViewColumn* /* column */); + void _buttonEventsSelectObjs(GdkEventButton *event); + void _selectObjects(int, int); void _checkAllChildren(Gtk::TreeModel::Children& children); Inkscape::XML::Node *_styleElementNode(); void _updateStyleContent(); -- cgit v1.2.3 From f57322fc77c604c6102132b6a254280e1f597064 Mon Sep 17 00:00:00 2001 From: kamalpreetgrewal Date: Sat, 9 Jul 2016 16:04:31 +0530 Subject: Delete objects from selector by clicking '-' in front of objects (bzr r14949.1.44) --- src/ui/dialog/styledialog.cpp | 148 +++++++++++++++++++++++++++++------------- 1 file changed, 104 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp index 7e0cb135f..ac51e36c1 100644 --- a/src/ui/dialog/styledialog.cpp +++ b/src/ui/dialog/styledialog.cpp @@ -223,7 +223,7 @@ void StyleDialog::_addSelector() getRepr()-> attribute("class")) + " " + textEditPtr->get_text() - .erase(0,0)); + .erase(0,1)); } } } @@ -296,46 +296,43 @@ void StyleDialog::_updateStyleContent() * This function deletes selector when '-' at the bottom is clicked. The index * of selected row is obtained and the corresponding selector and its values are * deleted from the selector vector. If a row has no parent, it is directly - * erased from the vector else the string containing selector row's selector value - * is updated after parsing. + * erased from the vector along with its child rows. The style element is updated + * accordingly. */ void StyleDialog::_delSelector() { Glib::RefPtr refTreeSelection = _treeView.get_selection(); Gtk::TreeModel::iterator iter = refTreeSelection->get_selected(); - Gtk::TreeModel::Path path; - if (iter) { Gtk::TreeModel::Row row = *iter; - path = _treeView.get_model()->get_path(iter); - int i = atoi(path.to_string().c_str()); + std::string sel, key, value; + std::vector<_selectorVecType>::iterator it; + for (it = _selectorVec.begin(); it != _selectorVec.end(); ++it ) { + sel = (*it).second; + REMOVE_SPACES(sel); + if (!sel.empty()) { + key = strtok(strdup(sel.c_str()), "{"); + REMOVE_SPACES(key); + char *temp = strtok(NULL, "}"); + if (strtok(temp, "}") != NULL) { + value = strtok(temp, "}"); + } + } + } if (_selectorVec.size() != 0) { if (!row.parent()) { - _selectorVec.erase(_selectorVec.begin()+i); - } - else { - std::string sel, key, value; - for (unsigned it = 0; it < _selectorVec.size(); ++it) { - sel = _selectorVec[it].second; - REMOVE_SPACES(sel); - std::cout << "sel" << sel << std::endl; - if (!sel.empty()) { - key = strtok(strdup(sel.c_str()), "{"); - REMOVE_SPACES(key); - char *temp = strtok(NULL, "}"); - if (strtok(temp, "}") != NULL) { - value = strtok(temp, "}"); - } - if (key == "#" + row[_mColumns._selectorLabel]) { - sel = ""; - } - else { - sel = sel; + if (!row.children().empty()) { + for (Gtk::TreeModel::Children::iterator child = row.children().begin(); + child != row.children().end(); ++child) { + Gtk::TreeModel::Row childrow = *child; + if (key == childrow[_mColumns._selectorLabel]) { + _selectorVec.erase(it); } - _selectorVec[it].second = sel; } } + _selectorVec.erase(it); + _store->erase(row); } /** @@ -351,7 +348,6 @@ void StyleDialog::_delSelector() _updateStyleContent(); } } - _store->erase(row); } } @@ -537,22 +533,29 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) int y2 = 0; if (_treeView.get_path_at_pos(x, y, path, col, x2, y2)) { if (col == _treeView.get_column(0)) { - if (_desktop->selection) { - std::vectorsel = _desktop->selection->list(); - for (unsigned i = 0; i < sel.size(); ++i) { - SPObject *obj = sel[i]; - Glib::RefPtr refTreeSelection = - _treeView.get_selection(); - Gtk::TreeModel::iterator iter = refTreeSelection-> - get_selected(); - - if (iter) - { - path = _treeView.get_model()->get_path(iter); - Gtk::TreeModel::Row row = *iter; + Glib::RefPtr refTreeSelection = + _treeView.get_selection(); + Gtk::TreeModel::iterator iter = refTreeSelection-> + get_selected(); + Gtk::TreeModel::Row row = *iter; + + /** + * This adds child rows to selected rows. If the parent row is + * a class selector, then the class attribute of object added + * to child row is appended with class in the parent row. The + * else below deletes objects from selectors when 'delete' button + * in front of child row is clicked. The class attribute is updated + * by removing the parent row's class selector name. + */ + if (!row.parent()) { + if (_desktop->selection) { + std::vectorsel = _desktop->selection->list(); + for (unsigned i = 0; i < sel.size(); ++i) { + SPObject *obj = sel[i]; std::string childStyle; - if (_selectorVec.size() != 0) { - if (!row.parent()) { + if (iter) { + path = _treeView.get_model()->get_path(iter); + if (_selectorVec.size() != 0) { Gtk::TreeModel::Row childrow; childrow = *(_store->append(row->children())); childrow[_mColumns._selectorLabel] = "#" + @@ -561,6 +564,19 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) childrow[_mColumns._colObj] = _desktop->selection->list(); childStyle = "#" + std::string(obj->getId()) + "{" + std::string(obj->getAttribute("style")) + "}\n"; + Glib::ustring key = row[_mColumns._selectorLabel]; + if (strcmp(key.substr(0,1).c_str(), ".") == 0) { + if (!obj->getRepr()->attribute("class")) { + obj->setAttribute("class", key.erase(0,1)); + } + else { + obj->setAttribute("class", std::string + (obj->getRepr()-> + attribute("class")) + + " " + key + .erase(0,1)); + } + } } } @@ -578,6 +594,50 @@ bool StyleDialog::_handleButtonEvent(GdkEventButton *event) } } } + + else { + std::string sel, key, value; + std::vector<_selectorVecType>::iterator it; + for (it = _selectorVec.begin(); it != _selectorVec.end(); ++it ) { + sel = (*it).second; + REMOVE_SPACES(sel); + if (!sel.empty()) { + key = strtok(strdup(sel.c_str()), "{"); + REMOVE_SPACES(key); + char *temp = strtok(NULL, "}"); + if (strtok(temp, "}") != NULL) { + value = strtok(temp, "}"); + } + } + } + if (key == row[_mColumns._selectorLabel]) { + Gtk::TreeModel::Row parentRow = *(row.parent()); + Glib::ustring parentKey = parentRow[_mColumns._selectorLabel]; + if (strcmp(parentKey.substr(0,1).c_str(), ".") == 0) { + std::vector objVec = row[_mColumns._colObj]; + for (unsigned i = 0; i < objVec.size(); ++i) { + SPObject *obj = objVec[i]; + std::string classAttr = std::string(obj->getRepr() + ->attribute("class")); + std::size_t found = classAttr.find(parentKey.erase(0,1)); + if (found != std::string::npos) { + classAttr.erase(found, parentKey.length()+1); + obj->getRepr()->setAttribute("class", classAttr); + } + } + } + _selectorVec.erase(it); + } + + if (_styleChild) { + _updateStyleContent(); + } + else { + _styleChild = _styleElementNode(); + _updateStyleContent(); + } + _store->erase(row); + } } } } -- cgit v1.2.3 From dca182031f3a9c95ae6a1f06c139a89c298846a1 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 10 Jul 2016 16:51:02 +0200 Subject: Improve font editing dialog: 1. Allow for fonts with other than 1000 units per em. 2. Allow setting 'ascent', 'descent', etc. 3. Allow setting individual glyph horizontal advances. 4. Fix bug where 'units-per-em' was not read correctly. (bzr r15014.1.1) --- src/display/nr-svgfonts.cpp | 42 ++++++--- src/display/nr-svgfonts.h | 3 +- src/sp-font.cpp | 6 +- src/ui/dialog/svg-fonts-dialog.cpp | 182 +++++++++++++++++++++++++++++-------- src/ui/dialog/svg-fonts-dialog.h | 37 +++++++- 5 files changed, 215 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/display/nr-svgfonts.cpp b/src/display/nr-svgfonts.cpp index 011f51977..3f8113de8 100644 --- a/src/display/nr-svgfonts.cpp +++ b/src/display/nr-svgfonts.cpp @@ -197,6 +197,7 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/, bool is_horizontal_text = true; //TODO _utf8 = (char*) utf8; + double font_height = units_per_em(); while(g_utf8_get_char(_utf8)){ len = 0; for (i=0; i < (unsigned long) this->glyphs.size(); i++){ @@ -207,11 +208,11 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/, //apply glyph kerning if appropriate SPHkern *hkern = dynamic_cast(node); if (hkern && is_horizontal_text && MatchHKerningRule(hkern, this->glyphs[i], previous_unicode, previous_glyph_name) ){ - x -= (hkern->k / 1000.0);//TODO: use here the height of the font + x -= (hkern->k / font_height); } SPVkern *vkern = dynamic_cast(node); if (vkern && !is_horizontal_text && MatchVKerningRule(vkern, this->glyphs[i], previous_unicode, previous_glyph_name) ){ - y -= (vkern->k / 1000.0);//TODO: use here the "height" of the font + y -= (vkern->k / font_height); } } previous_unicode = const_cast(this->glyphs[i]->unicode.c_str());//used for kerning checking @@ -221,8 +222,15 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/, (*glyphs)[count++].y = y; //advance glyph coordinates: - if (is_horizontal_text) x+=(this->font->horiz_adv_x/1000.0);//TODO: use here the height of the font - else y+=(this->font->vert_adv_y/1000.0);//TODO: use here the "height" of the font + if (is_horizontal_text) { + if (this->glyphs[i]->horiz_adv_x != 0) { + x+=(this->glyphs[i]->horiz_adv_x/font_height); + } else { + x+=(this->font->horiz_adv_x/font_height); + } + } else { + y+=(this->font->vert_adv_y/font_height); + } _utf8+=len; //advance 'len' bytes in our string pointer //continue; goto raptorz; @@ -235,8 +243,8 @@ SvgFont::scaled_font_text_to_glyphs (cairo_scaled_font_t */*scaled_font*/, (*glyphs)[count++].y = y; //advance glyph coordinates: - if (is_horizontal_text) x+=(this->font->horiz_adv_x/1000.0);//TODO: use here the height of the font - else y+=(this->font->vert_adv_y/1000.0);//TODO: use here the "height" of the font + if (is_horizontal_text) x+=(this->font->horiz_adv_x/font_height);//TODO: use here the height of the font + else y+=(this->font->vert_adv_y/font_height);//TODO: use here the "height" of the font _utf8 = g_utf8_next_char(_utf8); //advance 1 char in our string pointer } @@ -252,9 +260,7 @@ SvgFont::render_glyph_path(cairo_t* cr, Geom::PathVector* pathv){ cairo_new_path(cr); //adjust scale of the glyph -// Geom::Scale s(1.0/((SPFont*) node->parent)->horiz_adv_x); - Geom::Scale s(1.0/1000);//TODO: use here the units-per-em attribute? - + Geom::Scale s(1.0/units_per_em()); Geom::Rect area( Geom::Point(0,0), Geom::Point(1,1) ); //I need help here! (reaction: note that the 'area' parameter is an *optional* rect, so you can pass an empty Geom::OptRect() ) feed_pathvector_to_cairo (cr, *pathv, s, area, false, 0); @@ -270,11 +276,11 @@ SvgFont::glyph_modified(SPObject* /* blah */, unsigned int /* bleh */){ Geom::PathVector SvgFont::flip_coordinate_system(SPFont* spfont, Geom::PathVector pathv){ - double units_per_em = 1000; + double units_per_em = 1024; for (SPObject *obj = spfont->children; obj; obj = obj->next){ if (dynamic_cast(obj)) { //XML Tree being directly used here while it shouldn't be. - sp_repr_get_double(obj->getRepr(), "units_per_em", &units_per_em); + sp_repr_get_double(obj->getRepr(), "units-per-em", &units_per_em); } } @@ -395,6 +401,20 @@ void SvgFont::refresh(){ this->userfont = NULL; } +double SvgFont::units_per_em() { + double units_per_em = 1024; + for (SPObject *obj = font->children; obj; obj = obj->next){ + if (dynamic_cast(obj)) { + //XML Tree being directly used here while it shouldn't be. + sp_repr_get_double(obj->getRepr(), "units-per-em", &units_per_em); + } + } + if (units_per_em <= 0.0) { + units_per_em = 1024; + } + return units_per_em; +} + /* Local Variables: mode:c++ diff --git a/src/display/nr-svgfonts.h b/src/display/nr-svgfonts.h index 21ab3ed02..d4488fb17 100644 --- a/src/display/nr-svgfonts.h +++ b/src/display/nr-svgfonts.h @@ -52,7 +52,8 @@ private: SPMissingGlyph* missingglyph; sigc::connection glyph_modified_connection; - bool drawing_expose_cb (Gtk::Widget *widget, GdkEventExpose *event, void* data); + double units_per_em(); + //bool drawing_expose_cb (Gtk::Widget *widget, GdkEventExpose *event, void* data); }; #endif //#ifndef NR_SVGFONTS_H_SEEN diff --git a/src/sp-font.cpp b/src/sp-font.cpp index 341a6159f..6bdb24cf6 100644 --- a/src/sp-font.cpp +++ b/src/sp-font.cpp @@ -27,9 +27,9 @@ //I think we should have extra stuff here and in the set method in order to set default value as specified at http://www.w3.org/TR/SVG/fonts.html // TODO determine better values and/or make these dynamic: -double FNT_DEFAULT_ADV = 90; // TODO determine proper default -double FNT_DEFAULT_ASCENT = 90; // TODO determine proper default -double FNT_UNITS_PER_EM = 90; // TODO determine proper default +double FNT_DEFAULT_ADV = 1024; // TODO determine proper default +double FNT_DEFAULT_ASCENT = 768; // TODO determine proper default +double FNT_UNITS_PER_EM = 1024; // TODO determine proper default SPFont::SPFont() : SPObject() { this->horiz_origin_x = 0; diff --git a/src/ui/dialog/svg-fonts-dialog.cpp b/src/ui/dialog/svg-fonts-dialog.cpp index 08ebbcf14..3672fbe9e 100644 --- a/src/ui/dialog/svg-fonts-dialog.cpp +++ b/src/ui/dialog/svg-fonts-dialog.cpp @@ -31,6 +31,7 @@ #include "sp-font-face.h" #include "desktop.h" +#include #include "display/nr-svgfonts.h" #include "verbs.h" #include "sp-glyph.h" @@ -76,6 +77,15 @@ bool SvgFontDrawingArea::on_expose_event (GdkEventExpose */*event*/){ cr->set_font_size (_y-20); cr->move_to (10, 10); cr->show_text (_text.c_str()); + + // Draw some lines to show line area. + cr->set_source_rgb( 0.5, 0.5, 0.5 ); + cr->move_to ( 0, 10); + cr->line_to (_x, 10); + cr->stroke(); + cr->move_to ( 0, _y-10); + cr->line_to (_x, _y-10); + cr->stroke(); } return TRUE; } @@ -112,6 +122,7 @@ void SvgFontsDialog::AttrEntry::set_text(char* t){ entry.set_text(t); } +// 'font-family' has a problem as it is also a presentation attribute for void SvgFontsDialog::AttrEntry::on_attr_changed(){ SPObject* o = NULL; @@ -141,6 +152,74 @@ void SvgFontsDialog::AttrEntry::on_attr_changed(){ } +SvgFontsDialog::AttrSpin::AttrSpin(SvgFontsDialog* d, gchar* lbl, const SPAttributeEnum attr) { + + this->dialog = d; + this->attr = attr; + this->add(* Gtk::manage(new Gtk::Label(lbl)) ); + this->add(spin); + this->show_all(); + spin.set_range(0, 4096); + spin.set_increments(16, 0); + spin.signal_value_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::AttrSpin::on_attr_changed)); +} + +void SvgFontsDialog::AttrSpin::set_range(double low, double high){ + spin.set_range(low, high); +} + +void SvgFontsDialog::AttrSpin::set_value(double v){ + spin.set_value(v); +} + +void SvgFontsDialog::AttrSpin::on_attr_changed(){ + + SPObject* o = NULL; + switch (this->attr) { + + // attributes + case SP_ATTR_HORIZ_ORIGIN_X: + case SP_ATTR_HORIZ_ORIGIN_Y: + case SP_ATTR_HORIZ_ADV_X: + case SP_ATTR_VERT_ORIGIN_X: + case SP_ATTR_VERT_ORIGIN_Y: + case SP_ATTR_VERT_ADV_Y: + o = this->dialog->get_selected_spfont(); + break; + + // attributes + case SP_ATTR_UNITS_PER_EM: + case SP_ATTR_ASCENT: + case SP_ATTR_DESCENT: + case SP_ATTR_CAP_HEIGHT: + case SP_ATTR_X_HEIGHT: + for(SPObject* node = this->dialog->get_selected_spfont()->children; node; node=node->next){ + if (SP_IS_FONTFACE(node)){ + o = node; + continue; + } + } + break; + + default: + o = NULL; + } + + const gchar* name = (const gchar*)sp_attribute_name(this->attr); + if(name && o) { + std::ostringstream temp; + temp << this->spin.get_value(); + o->getRepr()->setAttribute((const gchar*) name, temp.str().c_str() ); + o->parent->requestModified(SP_OBJECT_MODIFIED_FLAG); + + Glib::ustring undokey = "svgfonts:"; + undokey += name; + DocumentUndo::maybeDone(o->document, undokey.c_str(), SP_VERB_DIALOG_SVG_FONTS, + _("Set SVG Font attribute")); + } + +} + Gtk::HBox* SvgFontsDialog::AttrCombo(gchar* lbl, const SPAttributeEnum /*attr*/){ Gtk::HBox* hbox = Gtk::manage(new Gtk::HBox()); hbox->add(* Gtk::manage(new Gtk::Label(lbl)) ); @@ -283,7 +362,6 @@ void SvgFontsDialog::update_fonts() } void SvgFontsDialog::on_preview_text_changed(){ - _font_da.set_text((gchar*) _preview_entry.get_text().c_str()); _font_da.set_text(_preview_entry.get_text()); } @@ -308,10 +386,19 @@ void SvgFontsDialog::update_global_settings_tab(){ SPFont* font = get_selected_spfont(); if (!font) return; + _horiz_adv_x_spin->set_value(font->horiz_adv_x); + _horiz_origin_x_spin->set_value(font->horiz_origin_x); + _horiz_origin_y_spin->set_value(font->horiz_origin_y); + SPObject* obj; for (obj=font->children; obj; obj=obj->next){ if (SP_IS_FONTFACE(obj)){ _familyname_entry->set_text((SP_FONTFACE(obj))->font_family); + _units_per_em_spin->set_value((SP_FONTFACE(obj))->units_per_em); + _ascent_spin->set_value((SP_FONTFACE(obj))->ascent); + _descent_spin->set_value((SP_FONTFACE(obj))->descent); + _x_height_spin->set_value((SP_FONTFACE(obj))->x_height); + _cap_height_spin->set_value((SP_FONTFACE(obj))->cap_height); } } } @@ -326,11 +413,8 @@ void SvgFontsDialog::on_font_selection_changed(){ kerning_preview.set_svgfont(svgfont); _font_da.set_svgfont(svgfont); _font_da.redraw(); - - double set_width = spfont->horiz_adv_x; - setwidth_spin.set_value(set_width); - - kerning_slider->set_range(0, set_width); + + kerning_slider->set_range(0, spfont->horiz_adv_x); kerning_slider->set_draw_value(false); kerning_slider->set_value(0); @@ -340,17 +424,6 @@ void SvgFontsDialog::on_font_selection_changed(){ update_sensitiveness(); } -void SvgFontsDialog::on_setfontdata_changed(){ - SPFont* spfont = this->get_selected_spfont(); - if (spfont){ - spfont->horiz_adv_x = setwidth_spin.get_value(); - //TODO: tell cairo that the glyphs cache has to be invalidated - // The current solution is to recreate the whole cairo svgfont. - // This is not a good solution to the issue because big fonts will result in poor performance. - update_glyphs(); - } -} - SPGlyphKerning* SvgFontsDialog::get_selected_kerning_pair() { Gtk::TreeModel::iterator i = _KerningPairsList.get_selection()->get_selected(); @@ -384,24 +457,37 @@ SPGlyph* SvgFontsDialog::get_selected_glyph() } Gtk::VBox* SvgFontsDialog::global_settings_tab(){ - _familyname_entry = new AttrEntry(this, (gchar*) _("Family Name:"), SP_PROP_FONT_FAMILY); + _font_label = new Gtk::Label( _("Font Attributes") ); + _horiz_adv_x_spin = new AttrSpin( this, (gchar*) _("Horiz. Advance X"), SP_ATTR_HORIZ_ADV_X); + _horiz_origin_x_spin = new AttrSpin( this, (gchar*) _("Horiz. Origin X "), SP_ATTR_HORIZ_ORIGIN_X); + _horiz_origin_y_spin = new AttrSpin( this, (gchar*) _("Horiz. Origin Y "), SP_ATTR_HORIZ_ORIGIN_Y); + _font_face_label = new Gtk::Label( _("Font Face Attributes") ); + _familyname_entry = new AttrEntry(this, (gchar*) _("Family Name:"), SP_PROP_FONT_FAMILY); + _units_per_em_spin = new AttrSpin( this, (gchar*) _("Units per em"), SP_ATTR_UNITS_PER_EM); + _ascent_spin = new AttrSpin( this, (gchar*) _("Ascent:"), SP_ATTR_ASCENT); + _descent_spin = new AttrSpin( this, (gchar*) _("Descent:"), SP_ATTR_DESCENT); + _cap_height_spin = new AttrSpin( this, (gchar*) _("Cap Height:"), SP_ATTR_CAP_HEIGHT); + _x_height_spin = new AttrSpin( this, (gchar*) _("x Height:"), SP_ATTR_X_HEIGHT); + + _descent_spin->set_range(-4096,0); + + global_vbox.pack_start(*_font_label, false, false); + global_vbox.pack_start(*_horiz_adv_x_spin, false, false); + global_vbox.pack_start(*_horiz_origin_x_spin, false, false); + global_vbox.pack_start(*_horiz_origin_y_spin, false, false); + global_vbox.pack_start(*_font_face_label, false, false); + global_vbox.pack_start(*_familyname_entry, false, false); + global_vbox.pack_start(*_units_per_em_spin, false, false); + global_vbox.pack_start(*_ascent_spin, false, false); + global_vbox.pack_start(*_descent_spin, false, false); + global_vbox.pack_start(*_cap_height_spin, false, false); + global_vbox.pack_start(*_x_height_spin, false, false); - global_vbox.pack_start(*_familyname_entry, false, false); /* global_vbox->add(*AttrCombo((gchar*) _("Style:"), SP_PROP_FONT_STYLE)); global_vbox->add(*AttrCombo((gchar*) _("Variant:"), SP_PROP_FONT_VARIANT)); global_vbox->add(*AttrCombo((gchar*) _("Weight:"), SP_PROP_FONT_WEIGHT)); */ -//Set Width (horiz_adv_x): - Gtk::HBox* setwidth_hbox = Gtk::manage(new Gtk::HBox()); - setwidth_hbox->add(*Gtk::manage(new Gtk::Label(_("Set width:")))); - setwidth_hbox->add(setwidth_spin); - - setwidth_spin.signal_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::on_setfontdata_changed)); - setwidth_spin.set_range(0, 4096); - setwidth_spin.set_increments(10, 0); - global_vbox.pack_start(*setwidth_hbox, false, false); - return &global_vbox; } @@ -417,9 +503,10 @@ SvgFontsDialog::populate_glyphs_box() for(SPObject* node = spfont->children; node; node=node->next){ if (SP_IS_GLYPH(node)){ Gtk::TreeModel::Row row = *(_GlyphsListStore->append()); - row[_GlyphsListColumns.glyph_node] = static_cast(node); + row[_GlyphsListColumns.glyph_node] = static_cast(node); row[_GlyphsListColumns.glyph_name] = (static_cast(node))->glyph_name; - row[_GlyphsListColumns.unicode] = (static_cast(node))->unicode; + row[_GlyphsListColumns.unicode] = (static_cast(node))->unicode; + row[_GlyphsListColumns.advance] = (static_cast(node))->horiz_adv_x; } } } @@ -492,7 +579,7 @@ void SvgFontsDialog::add_glyph(){ Geom::PathVector SvgFontsDialog::flip_coordinate_system(Geom::PathVector pathv){ - double units_per_em = 1000; + double units_per_em = 1024; SPObject* obj; for (obj = get_selected_spfont()->children; obj; obj=obj->next){ if (SP_IS_FONTFACE(obj)){ @@ -500,9 +587,7 @@ SvgFontsDialog::flip_coordinate_system(Geom::PathVector pathv){ sp_repr_get_double(obj->getRepr(), "units-per-em", &units_per_em); } } - double baseline_offset = units_per_em - get_selected_spfont()->horiz_origin_y; - //This matrix flips y-axis and places the origin at baseline Geom::Affine m(Geom::Coord(1),Geom::Coord(0),Geom::Coord(0),Geom::Coord(-1),Geom::Coord(0),Geom::Coord(baseline_offset)); return pathv*m; @@ -639,6 +724,26 @@ void SvgFontsDialog::glyph_unicode_edit(const Glib::ustring&, const Glib::ustrin update_glyphs(); } +void SvgFontsDialog::glyph_advance_edit(const Glib::ustring&, const Glib::ustring& str){ + Gtk::TreeModel::iterator i = _GlyphsList.get_selection()->get_selected(); + if (!i) return; + + SPGlyph* glyph = (*i)[_GlyphsListColumns.glyph_node]; + //XML Tree being directly used here while it shouldn't be. + std::istringstream is(str); + double value; + // Check if input valid + if ((is >> value)) { + glyph->getRepr()->setAttribute("horiz-adv-x", str.c_str()); + SPDocument* doc = this->getDesktop()->getDocument(); + DocumentUndo::done(doc, SP_VERB_DIALOG_SVG_FONTS, _("Set glyph advance")); + + update_glyphs(); + } else { + std::cerr << "SvgFontDialog::glyph_advance_edit: Error in input: " << str << std::endl; + } +} + void SvgFontsDialog::remove_selected_font(){ SPFont* font = get_selected_spfont(); if (!font) return; @@ -707,9 +812,9 @@ Gtk::VBox* SvgFontsDialog::glyphs_tab(){ _GlyphsListScroller.add(_GlyphsList); _GlyphsListStore = Gtk::ListStore::create(_GlyphsListColumns); _GlyphsList.set_model(_GlyphsListStore); - _GlyphsList.append_column_editable(_("Glyph name"), _GlyphsListColumns.glyph_name); + _GlyphsList.append_column_editable(_("Glyph name"), _GlyphsListColumns.glyph_name); _GlyphsList.append_column_editable(_("Matching string"), _GlyphsListColumns.unicode); - + _GlyphsList.append_column_numeric_editable(_("Advance"), _GlyphsListColumns.advance, "%.2f"); Gtk::HBox* hb = Gtk::manage(new Gtk::HBox()); add_glyph_button.set_label(_("Add Glyph")); add_glyph_button.signal_clicked().connect(sigc::mem_fun(*this, &SvgFontsDialog::add_glyph)); @@ -727,6 +832,9 @@ Gtk::VBox* SvgFontsDialog::glyphs_tab(){ dynamic_cast( _GlyphsList.get_column_cell_renderer(1))->signal_edited().connect( sigc::mem_fun(*this, &SvgFontsDialog::glyph_unicode_edit)); + dynamic_cast( _GlyphsList.get_column_cell_renderer(2))->signal_edited().connect( + sigc::mem_fun(*this, &SvgFontsDialog::glyph_advance_edit)); + _glyphs_observer.signal_changed().connect(sigc::mem_fun(*this, &SvgFontsDialog::update_glyphs)); return &glyphs_vbox; @@ -806,7 +914,7 @@ Gtk::VBox* SvgFontsDialog::kerning_tab(){ kerning_amount_hbox->add(*kerning_slider); kerning_preview.set_size(300 + 20, 150 + 20); - _font_da.set_size(150 + 20, 50 + 20); + _font_da.set_size(300 + 50 + 20, 60 + 20); return &kerning_vbox; } diff --git a/src/ui/dialog/svg-fonts-dialog.h b/src/ui/dialog/svg-fonts-dialog.h index e80bbfd39..11bf52187 100644 --- a/src/ui/dialog/svg-fonts-dialog.h +++ b/src/ui/dialog/svg-fonts-dialog.h @@ -86,8 +86,9 @@ public: void on_setfontdata_changed(); void add_font(); Geom::PathVector flip_coordinate_system(Geom::PathVector pathv); + bool updating; - //TODO: AttrEntry is currently unused. Should we remove it? + // Used for font-family class AttrEntry : public Gtk::HBox { public: @@ -100,6 +101,20 @@ public: SPAttributeEnum attr; }; + class AttrSpin : public Gtk::HBox + { + public: + AttrSpin(SvgFontsDialog* d, gchar* lbl, const SPAttributeEnum attr); + void set_value(double v); + void set_range(double low, double high); + Inkscape::UI::Widget::SpinButton* getSpin() { return &spin; } + private: + SvgFontsDialog* dialog; + void on_attr_changed(); + Inkscape::UI::Widget::SpinButton spin; + SPAttributeEnum attr; + }; + private: void update_glyphs(); void update_sensitiveness(); @@ -111,7 +126,8 @@ private: void reset_missing_glyph_description(); void add_glyph(); void glyph_unicode_edit(const Glib::ustring&, const Glib::ustring&); - void glyph_name_edit(const Glib::ustring&, const Glib::ustring&); + void glyph_name_edit( const Glib::ustring&, const Glib::ustring&); + void glyph_advance_edit(const Glib::ustring&, const Glib::ustring&); void remove_selected_glyph(); void remove_selected_font(); void remove_selected_kerning_pair(); @@ -133,7 +149,21 @@ private: Gtk::HBox* AttrCombo(gchar* lbl, const SPAttributeEnum attr); // Gtk::HBox* AttrSpin(gchar* lbl, const SPAttributeEnum attr); Gtk::VBox* global_settings_tab(); + + // + Gtk::Label* _font_label; + AttrSpin* _horiz_adv_x_spin; + AttrSpin* _horiz_origin_x_spin; + AttrSpin* _horiz_origin_y_spin; + + // + Gtk::Label* _font_face_label; AttrEntry* _familyname_entry; + AttrSpin* _units_per_em_spin; + AttrSpin* _ascent_spin; + AttrSpin* _descent_spin; + AttrSpin* _cap_height_spin; + AttrSpin* _x_height_spin; Gtk::VBox* kerning_tab(); Gtk::VBox* glyphs_tab(); @@ -169,11 +199,13 @@ private: add(glyph_node); add(glyph_name); add(unicode); + add(advance); } Gtk::TreeModelColumn glyph_node; Gtk::TreeModelColumn glyph_name; Gtk::TreeModelColumn unicode; + Gtk::TreeModelColumn advance; }; GlyphsColumns _GlyphsListColumns; Glib::RefPtr _GlyphsListStore; @@ -215,7 +247,6 @@ private: SvgFontDrawingArea _font_da, kerning_preview; GlyphComboBox first_glyph, second_glyph; SPGlyphKerning* kerning_pair; - Inkscape::UI::Widget::SpinButton setwidth_spin; #if WITH_GTKMM_3_0 Gtk::Scale* kerning_slider; -- cgit v1.2.3 From 1ba616c66fa080af9f6afc94af4e16247ed2dada Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Sun, 10 Jul 2016 18:38:29 +0200 Subject: Comment out unused enum. (bzr r15015) --- src/xml/event.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/xml/event.h b/src/xml/event.h index 73e68daeb..f6b734c29 100644 --- a/src/xml/event.h +++ b/src/xml/event.h @@ -33,13 +33,13 @@ namespace XML { /** * @brief Enumeration of all XML event types */ -enum EventType { - EVENT_ADD, ///< Child added - EVENT_DEL, ///< Child removed - EVENT_CHG_ATTR, ///< Attribute changed - EVENT_CHG_CONTENT, ///< Content changed - EVENT_CHG_ORDER ///< Order of children changed -}; +// enum EventType { +// EVENT_ADD, ///< Child added +// EVENT_DEL, ///< Child removed +// EVENT_CHG_ATTR, ///< Attribute changed +// EVENT_CHG_CONTENT, ///< Content changed +// EVENT_CHG_ORDER ///< Order of children changed +// }; /** * @brief Generic XML modification event -- cgit v1.2.3 From 058e95a59ccb2ab1748392acdfdbbffd516c9c81 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Mon, 11 Jul 2016 14:24:52 +0200 Subject: First part of new SPObject children list (bzr r14954.1.17) --- src/layer-fns.cpp | 36 +++++------- src/object-set.cpp | 18 +++--- src/selection-chemistry.cpp | 6 +- src/sp-item-group.cpp | 5 +- src/sp-item.cpp | 41 ++++--------- src/sp-mask.cpp | 15 ++--- src/sp-object.cpp | 124 ++++++++++++++++++++++----------------- src/sp-object.h | 29 +++++---- src/ui/widget/layer-selector.cpp | 20 ++----- src/uri-references.cpp | 2 +- 10 files changed, 139 insertions(+), 157 deletions(-) (limited to 'src') diff --git a/src/layer-fns.cpp b/src/layer-fns.cpp index 3e794a0a4..d149089db 100644 --- a/src/layer-fns.cpp +++ b/src/layer-fns.cpp @@ -36,11 +36,9 @@ bool is_layer(SPObject &object) { * @returns NULL if there are no further layers under a parent */ SPObject *next_sibling_layer(SPObject *layer) { - using std::find_if; - - return find_if( - layer->getNext(), NULL, &is_layer - ); + SPObject::ChildrenList &list = layer->parent->_children; + auto l = std::find_if(++list.iterator_to(*layer), list.end(), &is_layer); + return l != list.end() ? &*l : nullptr; } /** Finds the previous sibling layer for a \a layer @@ -50,11 +48,9 @@ SPObject *next_sibling_layer(SPObject *layer) { SPObject *previous_sibling_layer(SPObject *layer) { using Inkscape::Algorithms::find_last_if; - SPObject *sibling(find_last_if( - layer->parent->firstChild(), layer, &is_layer - )); - - return ( sibling != layer ) ? sibling : NULL; + SPObject::ChildrenList &list = layer->parent->_children; + auto l = find_last_if(list.begin(), list.iterator_to(*layer), &is_layer); + return l != list.iterator_to(*layer) ? &*(l) : nullptr; } /** Finds the first child of a \a layer @@ -62,16 +58,15 @@ SPObject *previous_sibling_layer(SPObject *layer) { * @returns NULL if layer has no sublayers */ SPObject *first_descendant_layer(SPObject *layer) { - using std::find_if; - - SPObject *first_descendant=NULL; - while (layer) { - layer = find_if( - layer->firstChild(), NULL, &is_layer - ); - if (layer) { + SPObject *first_descendant = nullptr; + while (true) { + auto tmp = std::find_if(layer->_children.begin(), layer->_children.end(), &is_layer); + if (tmp != layer->_children.end()) { first_descendant = layer; + } else { + break; } + layer = &*tmp; } return first_descendant; @@ -84,9 +79,8 @@ SPObject *first_descendant_layer(SPObject *layer) { SPObject *last_child_layer(SPObject *layer) { using Inkscape::Algorithms::find_last_if; - return find_last_if( - layer->firstChild(), NULL, &is_layer - ); + auto l = find_last_if(layer->_children.begin(), layer->_children.end(), &is_layer); + return l != layer->_children.end() ? &*l : nullptr; } SPObject *last_elder_layer(SPObject *root, SPObject *layer) { diff --git a/src/object-set.cpp b/src/object-set.cpp index 07f9ea0c8..b7b84e163 100644 --- a/src/object-set.cpp +++ b/src/object-set.cpp @@ -93,14 +93,14 @@ bool ObjectSet::_anyAncestorIsInSet(SPObject *object) { } void ObjectSet::_removeDescendantsFromSet(SPObject *object) { - for (auto& child: object->childList(false)) { - if (includes(child)) { - _remove(child); + for (auto& child: object->_children) { + if (includes(&child)) { + _remove(&child); // there is certainly no children of this child in the set continue; } - _removeDescendantsFromSet(child); + _removeDescendantsFromSet(&child); } } @@ -130,8 +130,8 @@ SPObject *ObjectSet::_getMutualAncestor(SPObject *object) { bool flag = true; while (o->parent != nullptr) { - for (auto &child: o->parent->childList(false)) { - if(child != o && !includes(child)) { + for (auto &child: o->parent->_children) { + if(&child != o && !includes(&child)) { flag = false; break; } @@ -147,9 +147,9 @@ SPObject *ObjectSet::_getMutualAncestor(SPObject *object) { void ObjectSet::_removeAncestorsFromSet(SPObject *object) { SPObject* o = object; while (o->parent != nullptr) { - for (auto &child: o->parent->childList(false)) { - if (child != o) { - _add(child); + for (auto &child: o->parent->_children) { + if (&child != o) { + _add(&child); } } if (includes(o->parent)) { diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 4b5c3f921..1f34f798d 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -4261,11 +4261,11 @@ static void itemtree_map(void (*f)(SPItem *, SPDesktop *), SPObject *root, SPDes f(item, desktop); } } - for ( SPObject::SiblingIterator iter = root->firstChild() ; iter ; ++iter ) { + for (auto& child: root->_children) { //don't recurse into locked layers - SPItem *item = dynamic_cast(&*iter); + SPItem *item = dynamic_cast(&child); if (!(item && desktop->isLayer(item) && item->isLocked())) { - itemtree_map(f, iter, desktop); + itemtree_map(f, &child, desktop); } } } diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 70d2bc732..d775e306f 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -297,9 +297,8 @@ Geom::OptRect SPGroup::bbox(Geom::Affine const &transform, SPItem::BBoxType bbox } void SPGroup::print(SPPrintContext *ctx) { - std::vector l=this->childList(false); - for(std::vector::const_iterator i=l.begin();i!=l.end();++i){ - SPObject *o = *i; + for(auto& child: _children){ + SPObject *o = &child; SPItem *item = dynamic_cast(o); if (item) { item->invoke_print(ctx); diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 9fd6e8ecc..258a5cd14 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -308,50 +308,35 @@ bool is_item(SPObject const &object) { void SPItem::raiseToTop() { using Inkscape::Algorithms::find_last_if; - SPObject *topmost=find_last_if( - next, NULL, &is_item - ); - if (topmost) { + auto topmost = find_last_if(++parent->_children.iterator_to(*this), parent->_children.end(), &is_item); + if (topmost != parent->_children.end()) { getRepr()->parent()->changeOrder( getRepr(), topmost->getRepr() ); } } void SPItem::raiseOne() { - SPObject *next_higher=std::find_if( - next, NULL, &is_item - ); - if (next_higher) { + auto next_higher = std::find_if(++parent->_children.iterator_to(*this), parent->_children.end(), &is_item); + if (next_higher != parent->_children.end()) { Inkscape::XML::Node *ref = next_higher->getRepr(); getRepr()->parent()->changeOrder(getRepr(), ref); } } void SPItem::lowerOne() { - using Inkscape::Util::MutableList; - using Inkscape::Util::reverse_list; - - MutableList next_lower=std::find_if( - reverse_list( - parent->firstChild(), this - ), - MutableList(), - &is_item - ); - if (next_lower) { - ++next_lower; - Inkscape::XML::Node *ref = ( next_lower ? next_lower->getRepr() : NULL ); + using Inkscape::Algorithms::find_last_if; + + auto next_lower = find_last_if(parent->_children.begin(), parent->_children.iterator_to(*this), &is_item); + if (next_lower != parent->_children.iterator_to(*this)) { + next_lower--; + Inkscape::XML::Node *ref = next_lower->getRepr(); getRepr()->parent()->changeOrder(getRepr(), ref); } } void SPItem::lowerToBottom() { - using Inkscape::Algorithms::find_last_if; - using Inkscape::Util::MutableList; - using Inkscape::Util::reverse_list; - - SPObject * bottom=parent->firstChild(); - while(dynamic_cast(bottom) && dynamic_cast(bottom->next) && bottom!=this && !is_item(*(bottom->next))) bottom=bottom->next; - if (bottom && bottom != this) { + auto bottom = std::find_if(parent->_children.begin(), parent->_children.iterator_to(*this), &is_item); + if (bottom != parent->_children.iterator_to(*this)) { + bottom--; Inkscape::XML::Node *ref = bottom->getRepr() ; parent->getRepr()->changeOrder(getRepr(), ref); } diff --git a/src/sp-mask.cpp b/src/sp-mask.cpp index 3537c7bac..a36d8ef29 100644 --- a/src/sp-mask.cpp +++ b/src/sp-mask.cpp @@ -138,12 +138,8 @@ void SPMask::update(SPCtx* ctx, unsigned int flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; - std::vector children = this->childList(false); - for (std::vector::const_iterator child = children.begin();child != children.end();++child) { - sp_object_ref(*child); - } - - + std::vector children = this->childList(true); + for (std::vector::const_iterator child = children.begin();child != children.end();++child) { if (flags || ((*child)->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { (*child)->updateDisplay(ctx, flags); @@ -172,11 +168,8 @@ void SPMask::modified(unsigned int flags) { flags &= SP_OBJECT_MODIFIED_CASCADE; - std::vector children = this->childList(false); - for (std::vector::const_iterator child = children.begin();child != children.end();++child) { - sp_object_ref(*child); - } - + std::vector children = this->childList(true); + for (std::vector::const_iterator child = children.begin();child != children.end();++child) { if (flags || ((*child)->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { (*child)->emitModified(flags); diff --git a/src/sp-object.cpp b/src/sp-object.cpp index d1659eedc..36957ab49 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -7,8 +7,9 @@ * Stephen Silver * Jon A. Cruz * Abhishek Sharma + * Adrian Boguszewski * - * Copyright (C) 1999-2008 authors + * Copyright (C) 1999-2016 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -16,6 +17,7 @@ #include #include +#include #include "helper/sp-marshal.h" #include "xml/node-event-vector.h" @@ -398,13 +400,12 @@ void SPObject::changeCSS(SPCSSAttr *css, gchar const *attr) } std::vector SPObject::childList(bool add_ref, Action) { - std::vector l; - for ( SPObject *child = firstChild() ; child; child = child->getNext() ) { + std::vector l; + for (auto& child: _children) { if (add_ref) { - sp_object_ref (child); + sp_object_ref(&child); } - - l.push_back(child); + l.push_back(&child); } return l; @@ -467,9 +468,9 @@ void SPObject::requestOrphanCollection() { } void SPObject::_sendDeleteSignalRecursive() { - for (SPObject *child = firstChild(); child; child = child->getNext()) { - child->_delete_signal.emit(child); - child->_sendDeleteSignalRecursive(); + for (auto& child: _children) { + child._delete_signal.emit(&child); + child._sendDeleteSignalRecursive(); } } @@ -497,12 +498,12 @@ void SPObject::deleteObject(bool propagate, bool propagate_descendants) void SPObject::cropToObject(SPObject *except) { std::vector toDelete; - for ( SPObject *child = this->firstChild(); child; child = child->getNext() ) { - if (SP_IS_ITEM(child)) { - if (child->isAncestorOf(except)) { - child->cropToObject(except); - } else if(child != except) { - toDelete.push_back(child); + for (auto& child: _children) { + if (SP_IS_ITEM(&child)) { + if (child.isAncestorOf(except)) { + child.cropToObject(except); + } else if(&child != except) { + toDelete.push_back(&child); } } } @@ -525,6 +526,12 @@ void SPObject::attach(SPObject *object, SPObject *prev) object->parent = this; this->_updateTotalHRefCount(object->_total_hrefcount); + auto it = _children.begin(); + if (prev != nullptr) { + it = ++_children.iterator_to(*prev); + } + _children.insert(it, *object); + SPObject *next; if (prev) { next = prev->next; @@ -541,43 +548,47 @@ void SPObject::attach(SPObject *object, SPObject *prev) object->xml_space.value = this->xml_space.value; } -void SPObject::reorder(SPObject *prev) -{ - //g_return_if_fail(object != NULL); - //g_return_if_fail(SP_IS_OBJECT(object)); - g_return_if_fail(this->parent != NULL); - g_return_if_fail(this != prev); - g_return_if_fail(!prev || SP_IS_OBJECT(prev)); - g_return_if_fail(!prev || prev->parent == this->parent); +void SPObject::reorder(SPObject* obj, SPObject* prev) { + g_return_if_fail(obj != nullptr); + g_return_if_fail(obj->parent); + g_return_if_fail(obj->parent == this); + g_return_if_fail(obj != prev); + g_return_if_fail(!prev || prev->parent == obj->parent); + + auto it = _children.begin(); + if (prev != nullptr) { + it = ++_children.iterator_to(*prev); + } + + _children.splice(it, _children, _children.iterator_to(*obj)); - SPObject *const parent=this->parent; SPObject *old_prev=NULL; - for ( SPObject *child = parent->children ; child && child != this ; + for ( SPObject *child = children ; child && child != obj ; child = child->next ) { old_prev = child; } - SPObject *next=this->next; + SPObject *next=obj->next; if (old_prev) { old_prev->next = next; } else { - parent->children = next; + children = next; } if (!next) { - parent->_last_child = old_prev; + _last_child = old_prev; } if (prev) { next = prev->next; - prev->next = this; + prev->next = obj; } else { - next = parent->children; - parent->children = this; + next = children; + children = obj; } - this->next = next; + obj->next = next; if (!next) { - parent->_last_child = this; + _last_child = obj; } } @@ -589,6 +600,7 @@ void SPObject::detach(SPObject *object) g_return_if_fail(SP_IS_OBJECT(object)); g_return_if_fail(object->parent == this); + _children.erase(_children.iterator_to(*object)); object->releaseReferences(); SPObject *prev=NULL; @@ -618,14 +630,14 @@ void SPObject::detach(SPObject *object) SPObject *SPObject::get_child_by_repr(Inkscape::XML::Node *repr) { g_return_val_if_fail(repr != NULL, NULL); - SPObject *result = 0; + SPObject *result = nullptr; - if ( _last_child && (_last_child->getRepr() == repr) ) { - result = _last_child; // optimization for common scenario + if (_children.size() > 0 && _children.back().getRepr() == repr) { + result = &_children.back(); // optimization for common scenario } else { - for ( SPObject *child = children ; child ; child = child->next ) { - if ( child->getRepr() == repr ) { - result = child; + for (auto& child: _children) { + if (child.getRepr() == repr) { + result = &child; break; } } @@ -656,10 +668,12 @@ void SPObject::child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) void SPObject::release() { SPObject* object = this; - debug("id=%p, typename=%s", object, g_type_name_from_instance((GTypeInstance*)object)); - while (object->children) { - object->detach(object->children); + auto tmp = _children | boost::adaptors::transformed([](SPObject& obj){return &obj;}); + std::vector toRelease(tmp.begin(), tmp.end()); + + for (auto& p: toRelease) { + object->detach(p); } } @@ -680,7 +694,7 @@ void SPObject::order_changed(Inkscape::XML::Node *child, Inkscape::XML::Node * / SPObject *ochild = object->get_child_by_repr(child); g_return_if_fail(ochild != NULL); SPObject *prev = new_ref ? object->get_child_by_repr(new_ref) : NULL; - ochild->reorder(prev); + object->reorder(ochild, prev); ochild->_position_changed_signal.emit(ochild); } @@ -1523,33 +1537,33 @@ bool SPObject::setTitleOrDesc(gchar const *value, gchar const *svg_tagname, bool return true; } -SPObject * SPObject::findFirstChild(gchar const *tagname) const +SPObject* SPObject::findFirstChild(gchar const *tagname) const { - for (SPObject *child = children; child; child = child->next) + for (auto& child: const_cast(this)->_children) { - if (child->repr->type() == Inkscape::XML::ELEMENT_NODE && - !strcmp(child->repr->name(), tagname)) { - return child; + if (child.repr->type() == Inkscape::XML::ELEMENT_NODE && + !strcmp(child.repr->name(), tagname)) { + return &child; } } - return NULL; + return nullptr; } char* SPObject::textualContent() const { GString* text = g_string_new(""); - for (const SPObject *child = firstChild(); child; child = child->next) + for (auto& child: _children) { - Inkscape::XML::NodeType child_type = child->repr->type(); + Inkscape::XML::NodeType child_type = child.repr->type(); if (child_type == Inkscape::XML::ELEMENT_NODE) { - char* new_string = child->textualContent(); + char* new_string = child.textualContent(); g_string_append(text, new_string); g_free(new_string); } else if (child_type == Inkscape::XML::TEXT_NODE) { - g_string_append(text, child->repr->content()); + g_string_append(text, child.repr->content()); } } return g_string_free(text, FALSE); @@ -1566,8 +1580,8 @@ void SPObject::recursivePrintTree( unsigned level ) std::cout << " "; } std::cout << (getId()?getId():"No object id") << std::endl; - for (SPObject *child = children; child; child = child->next) { - child->recursivePrintTree( level+1 ); + for (auto& child: _children) { + child.recursivePrintTree(level + 1); } } diff --git a/src/sp-object.h b/src/sp-object.h index 70d3e5df5..6aa006283 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -6,8 +6,9 @@ * Lauris Kaplinski * Jon A. Cruz * Abhishek Sharma + * Adrian Boguszewski * - * Copyright (C) 1999-2002 authors + * Copyright (C) 1999-2016 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -53,6 +54,7 @@ class SPObject; #include #include #include +#include #include "version.h" #include "util/forward-pointer-iterator.h" @@ -216,6 +218,7 @@ private: char *id; /* Our very own unique id */ Inkscape::XML::Node *repr; /* Our xml representation */ + public: int refCount; std::list hrefList; @@ -279,17 +282,9 @@ public: return object->parent; } }; - /// Switch containing next() method. - struct SiblingIteratorStrategy { - static SPObject const *next(SPObject const *object) { - return object->next; - } - }; typedef Inkscape::Util::ForwardPointerIterator ParentIterator; typedef Inkscape::Util::ForwardPointerIterator ConstParentIterator; - typedef Inkscape::Util::ForwardPointerIterator SiblingIterator; - typedef Inkscape::Util::ForwardPointerIterator ConstSiblingIterator; bool isSiblingOf(SPObject const *object) const { if (object == NULL) return false; @@ -317,7 +312,7 @@ public: */ SPObject *getPrev(); - bool hasChildren() const { return ( children != NULL ); } + bool hasChildren() const { return ( _children.size() > 0 ); } SPObject *firstChild() { return children; } SPObject const *firstChild() const { return children; } @@ -681,9 +676,9 @@ public: void attach(SPObject *object, SPObject *prev); /** - * In list of object's siblings, move object behind prev. + * In list of object's children, move object behind prev. */ - void reorder(SPObject *prev); + void reorder(SPObject* obj, SPObject *prev); /** * Remove object from parent's children, release and unref it. @@ -858,7 +853,17 @@ protected: virtual Inkscape::XML::Node* write(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, unsigned int flags); + typedef boost::intrusive::list_member_hook<> ListHook; + ListHook _child_hook; public: + typedef boost::intrusive::list< + SPObject, + boost::intrusive::member_hook< + SPObject, + ListHook, + &SPObject::_child_hook + >> ChildrenList; + ChildrenList _children; virtual void read_content(); void recursivePrintTree(unsigned level = 0); // For debugging diff --git a/src/ui/widget/layer-selector.cpp b/src/ui/widget/layer-selector.cpp index 1a9ce617f..46a0b3547 100644 --- a/src/ui/widget/layer-selector.cpp +++ b/src/ui/widget/layer-selector.cpp @@ -19,6 +19,8 @@ #include "ui/dialog/layer-properties.h" #include +#include +#include #include "desktop.h" @@ -348,27 +350,17 @@ void LayerSelector::_buildSiblingEntries( unsigned depth, SPObject &parent, Inkscape::Util::List hierarchy ) { - using Inkscape::Util::List; using Inkscape::Util::rest; - using Inkscape::Util::reverse_list_in_place; - using Inkscape::Util::filter_list; - Inkscape::Util::List siblings( - reverse_list_in_place( - filter_list( - is_layer(_desktop), parent.firstChild(), NULL - ) - ) - ); + auto siblings = parent._children | boost::adaptors::filtered(is_layer(_desktop)) | boost::adaptors::reversed; SPObject *layer( hierarchy ? &*hierarchy : NULL ); - while (siblings) { - _buildEntry(depth, *siblings); - if ( &*siblings == layer ) { + for (auto& sib: siblings) { + _buildEntry(depth, sib); + if ( &sib == layer ) { _buildSiblingEntries(depth+1, *layer, rest(hierarchy)); } - ++siblings; } } diff --git a/src/uri-references.cpp b/src/uri-references.cpp index db46a156f..078834131 100644 --- a/src/uri-references.cpp +++ b/src/uri-references.cpp @@ -92,7 +92,7 @@ bool URIReference::_acceptObject(SPObject *obj) const g_warning("cloned object with no known type\n"); return false; } - for (int i = positions.size() - 2; i >= 0; i--) + for (int i = (int) (positions.size() - 2); i >= 0; i--) owner = owner->childList(false)[positions[i]]; } // once we have the "original" object (hopefully) we look at who is referencing it -- cgit v1.2.3 From 798cda4430354143e90fb7ce81c3593a6dc24bc5 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah <> Date: Wed, 13 Jul 2016 08:12:57 +0530 Subject: Propagate changes to object tree with changes in style element (bzr r14949.1.46) --- src/path-chemistry.cpp | 6 +- src/sp-flowtext.cpp | 2 +- src/sp-object.cpp | 4 +- src/sp-style-elem.cpp | 25 ++++++- src/style-internal.cpp | 200 ++++++++++++++++++++++--------------------------- src/style-internal.h | 36 +++++++-- src/style.cpp | 160 +++++++++++++++++++-------------------- src/style.h | 7 +- 8 files changed, 233 insertions(+), 207 deletions(-) (limited to 'src') diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 1a345b565..f66c8cbf5 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -493,7 +493,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) /* Whole text's style */ Glib::ustring style_str = - item->style->write( SP_STYLE_FLAG_IFDIFF, item->parent ? item->parent->style : NULL); // TODO investigate posibility + item->style->write( SP_STYLE_FLAG_IFDIFF, SP_STYLE_SRC_UNSET, item->parent ? item->parent->style : NULL); // TODO investigate posibility g_repr->setAttribute("style", style_str.c_str()); Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); @@ -514,7 +514,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) pos_obj = pos_obj->parent; // SPStrings don't have style } Glib::ustring style_str = - pos_obj->style->write( SP_STYLE_FLAG_IFDIFF, pos_obj->parent ? pos_obj->parent->style : NULL); // TODO investigate posibility + pos_obj->style->write( SP_STYLE_FLAG_IFDIFF, SP_STYLE_SRC_UNSET, pos_obj->parent ? pos_obj->parent->style : NULL); // TODO investigate posibility // get path from iter to iter_next: SPCurve *curve = te_get_layout(item)->convertToCurves(iter, iter_next); @@ -573,7 +573,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) /* Style */ Glib::ustring style_str = - item->style->write( SP_STYLE_FLAG_IFDIFF, item->parent ? item->parent->style : NULL); // TODO investigate posibility + item->style->write( SP_STYLE_FLAG_IFDIFF, SP_STYLE_SRC_UNSET, item->parent ? item->parent->style : NULL); // TODO investigate posibility repr->setAttribute("style", style_str.c_str()); /* Mask */ diff --git a/src/sp-flowtext.cpp b/src/sp-flowtext.cpp index 51fb3ae89..90d4be87c 100644 --- a/src/sp-flowtext.cpp +++ b/src/sp-flowtext.cpp @@ -540,7 +540,7 @@ Inkscape::XML::Node *SPFlowtext::getAsText() this->layout.getSourceOfCharacter(it, &rawptr, &span_text_start_iter); SPObject *source_obj = reinterpret_cast(rawptr); - Glib::ustring style_text = (dynamic_cast(source_obj) ? source_obj->parent : source_obj)->style->write( SP_STYLE_FLAG_IFDIFF, this->style); + Glib::ustring style_text = (dynamic_cast(source_obj) ? source_obj->parent : source_obj)->style->write( SP_STYLE_FLAG_IFDIFF, SP_STYLE_SRC_UNSET, this->style); if (!style_text.empty()) { span_tspan->setAttribute("style", style_text.c_str()); } diff --git a/src/sp-object.cpp b/src/sp-object.cpp index d1659eedc..6d36ec833 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -1043,7 +1043,9 @@ Inkscape::XML::Node* SPObject::write(Inkscape::XML::Document *doc, Inkscape::XML } if (style) { - Glib::ustring s = style->write(SP_STYLE_FLAG_IFSET); + // Write if property set by style attribute in this object + Glib::ustring s = + style->write(SP_STYLE_FLAG_IFSET & SP_STYLE_FLAG_IFSRC, SP_STYLE_SRC_STYLE_PROP); // Check for valid attributes. This may be time consuming. // It is useful, though, for debugging Inkscape code. diff --git a/src/sp-style-elem.cpp b/src/sp-style-elem.cpp index 80e45677c..0f5af619b 100644 --- a/src/sp-style-elem.cpp +++ b/src/sp-style-elem.cpp @@ -3,6 +3,7 @@ #include "xml/repr.h" #include "document.h" #include "sp-style-elem.h" +#include "sp-root.h" #include "attributes.h" #include "style.h" using Inkscape::XML::TEXT_NODE; @@ -64,6 +65,7 @@ content_changed_cb(Inkscape::XML::Node *, gchar const *, gchar const *, SPObject *obj = reinterpret_cast(data); g_assert(data != NULL); obj->read_content(); + obj->document->getRoot()->emitModified( SP_OBJECT_MODIFIED_CASCADE ); } static void @@ -249,6 +251,19 @@ property_cb(CRDocHandler *const a_handler, g_return_if_fail(append_status == CR_OK); } +void update_style_recursively( SPObject *object ) { + if (object) { + // std::cout << "update_style_recursively: " + // << (object->getId()?object->getId():"null") << std::endl; + if (object->style) { + object->style->readFromObject( object ); + } + for (SPObject *child = object->children; child; child = child->next) { + update_style_recursively( child ); + } + } +} + void SPStyleElem::read_content() { /* fixme: If there's more than one