diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-03-19 18:26:22 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-03-19 18:26:22 +0000 |
| commit | aeffc3f474c1ce460b2c9f8340de283d5853a164 (patch) | |
| tree | 5ed8e1047308d0d2db0baefa8f1ee38b261b6da1 /src | |
| parent | commit for refactoring (diff) | |
| download | inkscape-aeffc3f474c1ce460b2c9f8340de283d5853a164.tar.gz inkscape-aeffc3f474c1ce460b2c9f8340de283d5853a164.zip | |
fixing a boring bug in path manipulator
(bzr r13645.1.43)
Diffstat (limited to 'src')
| -rw-r--r-- | src/2geom/pointwise.cpp | 472 | ||||
| -rw-r--r-- | src/2geom/pointwise.h | 31 | ||||
| -rw-r--r-- | src/2geom/satellite.cpp | 19 | ||||
| -rw-r--r-- | src/2geom/satellite.h | 34 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.cpp | 113 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.cpp | 17 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.h | 5 | ||||
| -rw-r--r-- | src/live_effects/parameter/satellitepairarray.cpp | 59 | ||||
| -rw-r--r-- | src/ui/tool/path-manipulator.cpp | 38 |
9 files changed, 425 insertions, 363 deletions
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<D2<SBasis> > pwd2, std::vector<std::pair<unsigned int,Satellite> > satellites) - : _pwd2(pwd2), _satellites(satellites) +Pointwise::Pointwise(Piecewise<D2<SBasis> > pwd2) + : _pwd2(pwd2),_pathInfo(NULL), _satellites(NULL) { + setPathInfo(); }; Pointwise::~Pointwise(){}; -std::vector<std::pair<unsigned int,Satellite> > -Pointwise::getSatellites(){ +Piecewise<D2<SBasis> > +Pointwise::getPwd2() const +{ + return _pwd2; +} + +void +Pointwise::setPwd2(Piecewise<D2<SBasis> > pwd2_in) +{ + _pwd2 = pwd2_in; + setPathInfo(); +} + +std::vector<std::pair<unsigned int,Satellite> > +Pointwise::getSatellites() const +{ return _satellites; } void -Pointwise::setSatellites(std::vector<std::pair<unsigned int,Satellite> > sat){ - _satellites = sat; +Pointwise::setSatellites(std::vector<std::pair<unsigned int,Satellite> > sats) +{ + _satellites = sats; } -Piecewise<D2<SBasis> > -Pointwise::getPwd2(){ - return _pwd2; +//START QUESTION Next functions maybe is beter land outside the class? +void +Pointwise::setPathInfo() +{ + setPathInfo(_pwd2); } void -Pointwise::setPwd2(Piecewise<D2<SBasis> > pwd2_in){ - _pwd2 = pwd2_in; +Pointwise::setPathInfo(Piecewise<D2<SBasis> > pwd2) +{ + _pathInfo.clear(); + std::vector<Geom::Path> 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<unsigned int> +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<unsigned int> +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<D2<SBasis> > A) { @@ -76,90 +192,132 @@ Pointwise::recalculate_for_new_pwd2(Piecewise<D2<SBasis> > A) void Pointwise::new_pwd_append(Piecewise<D2<SBasis> > A) { - int counter = 0; - double last = -1; - std::vector<std::pair<unsigned int,Satellite> > 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<std::pair<unsigned int,Satellite> > 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<D2<SBasis> > A) { int counter = 0; - double last = -1; - double start = false; - double hideLast = false; - std::vector<std::pair<unsigned int,Satellite> > satellites; - std::cout << _pwd2.size() << "pwsize\n"; - std::cout << A.size() << "Asize\n"; + std::vector<std::pair<unsigned int,Satellite> > sats; + Piecewise<D2<SBasis> > 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<unsigned int,Geom::Satellite> satellite) +Pointwise::rad_to_len(double A, std::pair<unsigned int,Geom::Satellite> sat) const { double len = 0; - boost::optional<Geom::D2<Geom::SBasis> > d2_in = getCurveIn(satellite); - if(d2_in){ - Geom::D2<Geom::SBasis> d2_out = _pwd2[satellite.first]; - Piecewise<D2<SBasis> > offset_curve0 = Piecewise<D2<SBasis> >(*d2_in)+rot90(unitVector(derivative(*d2_in)))*(A); + boost::optional<unsigned int> d2_prev_index = getPrevious(sat.first); + if(d2_prev_index){ + Geom::D2<Geom::SBasis> d2_in = _pwd2[*d2_prev_index]; + Geom::D2<Geom::SBasis> d2_out = _pwd2[sat.first]; + Piecewise<D2<SBasis> > offset_curve0 = Piecewise<D2<SBasis> >(d2_in)+rot90(unitVector(derivative(d2_in)))*(A); Piecewise<D2<SBasis> > offset_curve1 = Piecewise<D2<SBasis> >(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<unsigned int,Geom::Satellite> 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<unsigned int,Geom::Satellite> satelli } double -Pointwise::len_to_rad(double A, std::pair<unsigned int,Geom::Satellite> satellite) +Pointwise::len_to_rad(double A, std::pair<unsigned int,Geom::Satellite> sat) const { - boost::optional<Geom::D2<Geom::SBasis> > d2_in = getCurveIn(satellite); - if(d2_in){ - Geom::D2<Geom::SBasis> 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<unsigned int> d2_prev_index = getPrevious(sat.first); + if(d2_prev_index){ + Geom::D2<Geom::SBasis> d2_in = _pwd2[*d2_prev_index]; + Geom::D2<Geom::SBasis> 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<D2<SBasis> > 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<D2<SBasis> > u2; u2.push_cut(0); @@ -198,7 +357,7 @@ Pointwise::len_to_rad(double A, std::pair<unsigned int,Geom::Satellite> satelli Curve *knotCurve1 = A->portion(0, time_in); Curve *knotCurve2 = B->portion(time_out, 1); Geom::CubicBezier const *cubic1 = dynamic_cast<Geom::CubicBezier const *>(&*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<unsigned int,Geom::Satellite> 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<unsigned int,Geom::Satellite> satelli return 0; } -boost::optional<Geom::D2<Geom::SBasis> > -Pointwise::getCurveIn(std::pair<unsigned int,Satellite> sat){ - //curve out = sat.first; - std::vector<Geom::Path> 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<Satellite> Pointwise::findSatellites(unsigned int A, int B) const { @@ -281,96 +394,13 @@ Pointwise::findSatellites(unsigned int A, int B) const return ret; } -std::vector<std::pair<unsigned int,Satellite> > -Pointwise::setBackHidden(std::vector<std::pair<unsigned int,Satellite> > 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<std::pair<unsigned int,Satellite> > -Pointwise::setBackInactive(std::vector<std::pair<unsigned int,Satellite> > 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<std::pair<unsigned int,Satellite> > -Pointwise::setBackClosing(std::vector<std::pair<unsigned int,Satellite> > 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<Satellite> -Pointwise::findClosingSatellites(unsigned int A) const -{ - std::vector<Satellite> 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<Satellite> Pointwise::findPeviousSatellites(unsigned int A, int B) const { + boost::optional<unsigned int> previous = getPrevious(A); std::vector<Satellite> 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<D2<SBasis> > pwd2, std::vector<std::pair<unsigned int,Satellite> > satellites); + Pointwise(Piecewise<D2<SBasis> > pwd2); virtual ~Pointwise(); std::vector<Satellite> findSatellites(unsigned int A, int B = -1) const; std::vector<Satellite> findPeviousSatellites(unsigned int A, int B) const; - std::vector<Satellite> findClosingSatellites(unsigned int A) const; - double rad_to_len(double A, std::pair<unsigned int,Geom::Satellite> satellite); - double len_to_rad(double A, std::pair<unsigned int,Geom::Satellite> satellite); - std::vector<std::pair<unsigned int,Satellite> > getSatellites(); - void setSatellites(std::vector<std::pair<unsigned int,Satellite> > sat); - Piecewise<D2<SBasis> > getPwd2(); + double rad_to_len(double A, std::pair<unsigned int,Geom::Satellite> sat) const; + double len_to_rad(double A, std::pair<unsigned int,Geom::Satellite> sat) const; + std::vector<std::pair<unsigned int,Satellite> > getSatellites() const; + void setSatellites(std::vector<std::pair<unsigned int,Satellite> > sats); + Piecewise<D2<SBasis> > getPwd2() const; void setPwd2(Piecewise<D2<SBasis> > pwd2_in); - boost::optional<Geom::D2<Geom::SBasis> > getCurveIn(std::pair<unsigned int,Satellite> sat); void recalculate_for_new_pwd2(Piecewise<D2<SBasis> > A); void new_pwd_append(Piecewise<D2<SBasis> > A); void new_pwd_sustract(Piecewise<D2<SBasis> > A); - std::vector<std::pair<unsigned int,Satellite> > setBackClosing(std::vector<std::pair<unsigned int,Satellite> > sat); - std::vector<std::pair<unsigned int,Satellite> > setBackHidden(std::vector<std::pair<unsigned int,Satellite> > 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<D2<SBasis> >); + unsigned int getSubPathIndex(unsigned int index) const; + unsigned int getLast(unsigned int index) const; + unsigned int getFirst(unsigned int index) const; + boost::optional<unsigned int> getPrevious(unsigned int index) const; + boost::optional<unsigned int> getNext(unsigned int index) const; + bool getIsClosed(unsigned int index) const; private: Piecewise<D2<SBasis> > _pwd2; std::vector<std::pair<unsigned int,Satellite> > _satellites; - + std::vector<std::pair<unsigned int, bool> > _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<Geom::SBasis> d2_in) +Satellite::toTime(double A,Geom::D2<Geom::SBasis> d2_in) const { if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ return 0; @@ -71,7 +71,7 @@ Satellite::toTime(double A,Geom::D2<Geom::SBasis> d2_in) } double -Satellite::toSize(double A,Geom::D2<Geom::SBasis> d2_in) +Satellite::toSize(double A,Geom::D2<Geom::SBasis> d2_in) const { if(!d2_in.isFinite() || d2_in.isZero() || A == 0){ return 0; @@ -91,7 +91,7 @@ Satellite::toSize(double A,Geom::D2<Geom::SBasis> d2_in) } double -Satellite::getOpositeTime(double s, Geom::D2<Geom::SBasis> d2_in) +Satellite::getOpositeTime(double s, Geom::D2<Geom::SBasis> d2_in) const { if(s == 0){ return 1; @@ -102,7 +102,8 @@ Satellite::getOpositeTime(double s, Geom::D2<Geom::SBasis> d2_in) } double -Satellite::getTime(Geom::D2<Geom::SBasis> d2_in){ +Satellite::getTime(Geom::D2<Geom::SBasis> d2_in) const +{ double t = getAmount(); if(!getIsTime()){ t = toTime(t, d2_in); @@ -114,7 +115,8 @@ Satellite::getTime(Geom::D2<Geom::SBasis> d2_in){ } double -Satellite::getSize(Geom::D2<Geom::SBasis> d2_in){ +Satellite::getSize(Geom::D2<Geom::SBasis> d2_in) const +{ double s = getAmount(); if(getIsTime()){ s = toSize(s, d2_in); @@ -124,7 +126,8 @@ Satellite::getSize(Geom::D2<Geom::SBasis> d2_in){ Geom::Point -Satellite::getPosition(Geom::D2<Geom::SBasis> d2_in){ +Satellite::getPosition(Geom::D2<Geom::SBasis> 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<Geom::SBasis> d2_in); - Geom::Point getPosition(Geom::D2<Geom::SBasis> curve); - double getSize(Geom::D2<Geom::SBasis> d2_in); - double getTime(Geom::D2<Geom::SBasis> d2_in); - double getOpositeTime(double A,Geom::D2<Geom::SBasis> SBasisCurve); - double toSize(double A,Geom::D2<Geom::SBasis> d2_in); - double toTime(double A,Geom::D2<Geom::SBasis> d2_in); + Geom::Point getPosition(Geom::D2<Geom::SBasis> curve) const; + double getSize(Geom::D2<Geom::SBasis> d2_in) const; + double getTime(Geom::D2<Geom::SBasis> d2_in) const; + double getOpositeTime(double A,Geom::D2<Geom::SBasis> SBasisCurve) const; + double toSize(double A,Geom::D2<Geom::SBasis> d2_in) const; + double toTime(double A,Geom::D2<Geom::SBasis> 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<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); 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<LivePathEffect::LPEBSpline const*>(thisEffect->getLPEObj()->get_lpe()); + SPLPEItem * path = dynamic_cast<SPLPEItem *>(_path); + if (path){ + if(path->hasPathEffect()){ + Inkscape::LivePathEffect::Effect const *thisEffect = path->getPathEffectOfType(Inkscape::LivePathEffect::BSPLINE); + if(thisEffect){ + lpe_bsp = dynamic_cast<LivePathEffect::LPEBSpline const*>(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<LivePathEffect::LPEPowerStroke*>(thisEffect->getLPEObj()->get_lpe()); - if (lpe_pwr) { - lpe_pwr->adjustForNewPath(pathv); + SPLPEItem * path = dynamic_cast<SPLPEItem *>(_path); + if (path){ + if(path->hasPathEffect()){ + Inkscape::LivePathEffect::Effect* thisEffect = path->getPathEffectOfType(Inkscape::LivePathEffect::POWERSTROKE); + if(thisEffect){ + LivePathEffect::LPEPowerStroke *lpe_pwr = dynamic_cast<LivePathEffect::LPEPowerStroke*>(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<LivePathEffect::LPEFilletChamfer*>(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<LivePathEffect::LPEFilletChamfer*>(thisEffect->getLPEObj()->get_lpe()); + if (lpe_fll) { + lpe_fll->adjustForNewPath(pathv); + } } } } |
