diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2016-06-12 22:58:55 +0000 |
|---|---|---|
| committer | jabiertxof <info@marker.es> | 2016-06-12 22:58:55 +0000 |
| commit | 73f078b27b669c941651ecf14a3119ae491ccabf (patch) | |
| tree | 859d650d22f499e1b3af266bcd3e43ff39bdbc6f /src/helper | |
| parent | Handle both directions on knot reposition (diff) | |
| download | inkscape-73f078b27b669c941651ecf14a3119ae491ccabf.tar.gz inkscape-73f078b27b669c941651ecf14a3119ae491ccabf.zip | |
Fix 90% of tweenk review
(bzr r13645.1.155)
Diffstat (limited to 'src/helper')
| -rw-r--r-- | src/helper/geom-pathvectorsatellites.cpp | 111 | ||||
| -rw-r--r-- | src/helper/geom-pathvectorsatellites.h | 11 | ||||
| -rw-r--r-- | src/helper/geom-satellite.cpp | 58 | ||||
| -rw-r--r-- | src/helper/geom-satellite.h | 13 |
4 files changed, 143 insertions, 50 deletions
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<size_t, size_t> PathVectorSatellites::getIndexData(size_t index) return std::make_pair(0,0); } +void PathVectorSatellites::setSelected(std::vector<size_t> 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<size_t> 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<std::vector<Satellite> > 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<size_t> 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<size_t, size_t> 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<jabier.arraiza@marker.es> @@ -23,15 +23,14 @@ #include <ctime> #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<Geom::Curve *>(&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<std::string, SatelliteType> 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<SatelliteType, gchar const *> 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<jabier.arraiza@marker.es> @@ -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); |
