summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-05-14 21:52:45 +0000
committerjabiertxof <info@marker.es>2016-05-14 21:52:45 +0000
commit4c145e43f8ab8d8040fb2fa42309f7bd400f6349 (patch)
tree6f2336cd01002e50ee29f95ddf006b89c0e6fac4 /src
parentupdate to trunk (diff)
downloadinkscape-4c145e43f8ab8d8040fb2fa42309f7bd400f6349.tar.gz
inkscape-4c145e43f8ab8d8040fb2fa42309f7bd400f6349.zip
Fixing pointwise
(bzr r13645.1.135)
Diffstat (limited to 'src')
-rw-r--r--src/helper/geom-pointwise.cpp143
-rw-r--r--src/helper/geom-pointwise.h24
-rw-r--r--src/live_effects/lpe-fillet-chamfer.cpp95
-rw-r--r--src/live_effects/lpe-fillet-chamfer.h2
-rw-r--r--src/live_effects/parameter/array.cpp68
-rw-r--r--src/live_effects/parameter/array.h2
-rw-r--r--src/live_effects/parameter/satellitesarray.cpp231
-rw-r--r--src/live_effects/parameter/satellitesarray.h8
8 files changed, 191 insertions, 382 deletions
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 <helper/geom-pointwise.h>
-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<Satellite> 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<Satellite> 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<Satellite> 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<Satellite> 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<Geom::D2<Geom::SBasis> > 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 <helper/geom-satellite.h>
-#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 <boost/optional.hpp>
/**
- * @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<Geom::D2<Geom::SBasis> > PwD2SBasis;
typedef std::vector<std::vector<Satellite> > 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<SBasis>
- //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<size_t> curve_prev_index = boost::none;
+ boost::optional<size_t> 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<SPLPEItem *>(lpeItem);
SPShape *shape = dynamic_cast<SPShape *>(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<Geom::D2<Geom::SBasis> > 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<size_t> 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<Satellite> *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<double>::readsvg(const gchar * str)
@@ -89,11 +51,35 @@ template <>
std::vector<Satellite>
ArrayParam<std::vector<Satellite > >::readsvg(const gchar * str)
{
- std::vector<Satellite > subpath_satellites;
- if (sp_svg_satellite_vector_read_d(str, &subpath_satellites)) {
+ std::vector<Satellite> 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 <preferences.h>
-#include <boost/optional.hpp>
// TODO due to internal breakage in glibmm headers,
// this has to be included last.
#include <glibmm/i18n.h>
@@ -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<size_t> 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<Geom::Curve *>(&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<Geom::Curve *>(&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 = _("<b>Chamfer</b>: <b>Ctrl+Click</b> 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<size_t> 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<size_t> 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<size_t> 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<Geom::SBasis> d2_out = pathv[_index][subindex].toSBasis();
- if (curve_prev_index) {
- Geom::D2<Geom::SBasis> d2_in = pathv[_index][*curve_prev_index].toSBasis();
+ if (previous_index) {
+ Geom::D2<Geom::SBasis> 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<size_t> 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;
};