summaryrefslogtreecommitdiffstats
path: root/src/live_effects
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-03-19 18:26:22 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-03-19 18:26:22 +0000
commitaeffc3f474c1ce460b2c9f8340de283d5853a164 (patch)
tree5ed8e1047308d0d2db0baefa8f1ee38b261b6da1 /src/live_effects
parentcommit for refactoring (diff)
downloadinkscape-aeffc3f474c1ce460b2c9f8340de283d5853a164.tar.gz
inkscape-aeffc3f474c1ce460b2c9f8340de283d5853a164.zip
fixing a boring bug in path manipulator
(bzr r13645.1.43)
Diffstat (limited to 'src/live_effects')
-rw-r--r--src/live_effects/lpe-fillet-chamfer.cpp113
-rw-r--r--src/live_effects/parameter/array.cpp17
-rw-r--r--src/live_effects/parameter/array.h5
-rw-r--r--src/live_effects/parameter/satellitepairarray.cpp59
4 files changed, 113 insertions, 81 deletions
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<SPLPEItem*>(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<SPLPEItem*>(lpeItem);
@@ -278,13 +278,14 @@ void LPEFilletChamfer::updateAmount()
std::vector<std::pair<unsigned int,Geom::Satellite> > satellites = pointwise->getSatellites();
Piecewise<D2<SBasis> > pwd2 = pointwise->getPwd2();
for (std::vector<std::pair<unsigned int,Geom::Satellite> >::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<SPLPEItem *>(lpeItem);
SPShape * shape = dynamic_cast<SPShape *>(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<D2<SBasis> > pwd2_in = paths_to_pw(original_pathv);
pwd2_in = remove_short_cuts(pwd2_in, 0.01);
- std::vector<std::pair<unsigned int,Geom::Satellite> > satellites = satellitepairarrayparam_values.data();
- pointwise = new Pointwise(pwd2_in,satellites);
-
+ std::vector<std::pair<unsigned int,Geom::Satellite> > 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<std::pair<unsigned int,Geom::Satellite> >::iterator it = satellites.begin(); it != satellites.end(); ++it) {
+ for (std::vector<std::pair<unsigned int,Geom::Satellite> >::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<Geom::Path> 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<Geom::Path>
LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in)
{
+ std::cout << "doEffect_pathstart\n";
const double gapHelper = 0.00001;
std::vector<Geom::Path> pathvector_out;
unsigned int counter = 0;
@@ -447,6 +453,13 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> 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<Geom::Path> const &path_in)
std::vector<Satellite> 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<Geom::Path> 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<Geom::Path> 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<Geom::D2<Geom::SBasis> > curve_in = last_pointwise->getCurveIn(_vector[i]);
- if(curve_in){
- lenght_in = Geom::length(*curve_in, Geom::EPSILON);
+ boost::optional<unsigned int> 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<Geom::D2<Geom::SBasis> > pwd2 = pointwise->getPwd2();
if(_pparam->_vector.size() <= _index){
- boost::optional<Geom::D2<Geom::SBasis> > d2_in = pointwise->getCurveIn(satellite);
- if(d2_in){
- double mirrorTime = Geom::nearest_point(s, *d2_in);
+ boost::optional<unsigned int> d2_prev_index = pointwise->getPrevious(satellite.first);
+ if(d2_prev_index){
+ Geom::D2<Geom::SBasis> d2_in = pwd2[*d2_prev_index];
+ double mirrorTime = Geom::nearest_point(s, d2_in);
double timeStart = 0;
std::vector<Satellite> 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<Geom::D2<Geom::SBasis> > 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<Geom::D2<Geom::SBasis> > d2_in = pointwise->getCurveIn(satellite);
- if(d2_in){
+ boost::optional<unsigned int> d2_prev_index = pointwise->getPrevious(satellite.first);
+ if(d2_prev_index){
+ Geom::D2<Geom::SBasis> 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<Satellite> 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<Geom::D2<Geom::SBasis> > d2_in = _pparam->last_pointwise->getCurveIn(_pparam->_vector.at(index));
bool aprox = false;
D2<SBasis> 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<unsigned int> d2_prev_index = _pparam->last_pointwise->getPrevious(_pparam->_vector.at(index).first);
+ if(d2_prev_index){
+ Geom::D2<Geom::SBasis> 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);