diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-03-31 10:56:46 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-03-31 10:56:46 +0000 |
| commit | a1cd9b9c2fdb5b4258a14159a3a4baa2782e7d40 (patch) | |
| tree | 082b1b90fb1d19d6013ff44a019cddab76039b2a /src | |
| parent | update to trunk (diff) | |
| download | inkscape-a1cd9b9c2fdb5b4258a14159a3a4baa2782e7d40.tar.gz inkscape-a1cd9b9c2fdb5b4258a14159a3a4baa2782e7d40.zip | |
end append path
(bzr r13645.1.57)
Diffstat (limited to 'src')
| -rw-r--r-- | src/2geom/pointwise.cpp | 174 | ||||
| -rw-r--r-- | src/2geom/pointwise.h | 4 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.cpp | 64 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.h | 1 | ||||
| -rw-r--r-- | src/live_effects/parameter/satellitepairarray.cpp | 23 | ||||
| -rw-r--r-- | src/live_effects/parameter/satellitepairarray.h | 1 |
6 files changed, 207 insertions, 60 deletions
diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index b97f8749f..bc82780d7 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -183,13 +183,10 @@ void Pointwise::recalculate_for_new_pwd2(Piecewise<D2<SBasis> > A) { if( _pwd2.size() > A.size()){ - std::cout << "bbbbbbbbbbbbbbbbbbbbbbbbb\n"; pwd2_sustract(A); - } else if ( _pwd2.size() < A.size()){ + } else if (_pwd2.size() < A.size()){ pwd2_append(A); - std::cout << "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"; } - std::cout << "cccccccccccccccccccccccccccccccccc\n"; } void @@ -197,14 +194,39 @@ Pointwise::pwd2_append(Piecewise<D2<SBasis> > A) { size_t counter = 0; std::vector<std::pair<size_t,Satellite> > sats; - Piecewise<D2<SBasis> > pwd2 = _pwd2; - setPwd2(A); - std::cout << A.size() << "ASIZE\n"; - std::cout << pwd2.size() << "PWD2SIZE\n"; + for (std::vector<std::pair<size_t,Satellite> >::iterator it=_satellites.begin(); it!=_satellites.end();) + { + if(it->second.getIsEndOpen()){ + it = _satellites.erase(it); + } else { + ++it; + } + } + bool reversed = false; + bool reorder = false; for(size_t i = 0; i < A.size(); i++){ - std::cout << i << "indes\n"; - std::cout << counter << "counter\n"; - if(pwd2.size() <= i-counter || !are_near(pwd2[i-counter].at0(),A[i].at0(),0.001)){ + size_t first = getFirst(i-counter); + size_t last = getLast(i-counter); + setPathInfo(A); + size_t subpathAIndex = getSubPathIndex(i); + setPathInfo(_pwd2); + bool changedSubpath = false; + if(_pwd2.size() <= i-counter){ + changedSubpath = false; + } else { + changedSubpath = subpathAIndex != getSubPathIndex(i-counter); + } + if(!reorder && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ + subpath_append_reorder(getSubPathIndex(first)); + reorder = true; + i--; + continue; + } + if(!reversed && first == i-counter && !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001) && !changedSubpath){ + reverse(first, last); + reversed = true; + } + if(_pwd2.size() <= i-counter || !are_near(_pwd2[i-counter].at0(),A[i].at0(),0.001)){ counter++; bool isEndOpen = false; bool active = true; @@ -217,9 +239,13 @@ Pointwise::pwd2_append(Piecewise<D2<SBasis> > A) Satellite sat(_satellites[0].second.getSatelliteType(), isTime, isEndOpen, active, mirror_knots, hidden, amount, degrees, steps); sats.push_back(std::make_pair(i,sat)); } else { - sats.push_back(std::make_pair(i,_satellites[i-counter].second)); + std::vector<size_t> satsFind = findSatellites(i-counter,999); + for(size_t j = 0; j< satsFind.size(); j++){ + sats.push_back(std::make_pair(i,_satellites[satsFind[j]].second)); + } } } + setPwd2(A); setSatellites(sats); } @@ -228,9 +254,12 @@ Pointwise::pwd2_sustract(Piecewise<D2<SBasis> > A) { size_t counter = 0; std::vector<std::pair<size_t,Satellite> > sats; - for(size_t i = 0; i < _satellites.size(); i++){ - if(_satellites[i].second.getIsEndOpen()){ - _satellites.erase(_satellites.begin() + i); + for (std::vector<std::pair<size_t,Satellite> >::iterator it=_satellites.begin(); it!=_satellites.end();) + { + if(it->second.getIsEndOpen()){ + it = _satellites.erase(it); + } else { + ++it; } } Piecewise<D2<SBasis> > pwd2 = _pwd2; @@ -239,14 +268,17 @@ Pointwise::pwd2_sustract(Piecewise<D2<SBasis> > A) if(getLast(_satellites[i].first-counter) < _satellites[i].first-counter || !are_near(pwd2[_satellites[i].first].at0(),A[_satellites[i].first-counter].at0(),0.001)){ counter++; } else { - sats.push_back(std::make_pair(_satellites[i].first-counter,_satellites[i].second)); + std::vector<size_t> satsFind = findSatellites(_satellites[i].first-counter,999); + for(size_t j = 0; j< satsFind.size(); j++){ + sats.push_back(std::make_pair(_satellites[i].first-counter,_satellites[satsFind[j]].second)); + } } } setSatellites(sats); } void -Pointwise::set_extremes(bool endOpenSat,bool active, bool hidden, double amount, double angle) +Pointwise::set_extremes(bool active, bool hidden, double amount, double angle) { for(size_t i = 0; i < _pathInfo.size(); i++){ size_t firstNode = getFirst(_pathInfo[i].first); @@ -268,30 +300,96 @@ Pointwise::set_extremes(bool endOpenSat,bool active, bool hidden, double amount, _satellites[j].second.setAngle(angle); } } - - if(_satellites[j].first == lastNode && lastIndex != -1){ - _satellites[j].second.setIsEndOpen(true); - } - if(_satellites[j].first == lastNode && lastIndex == -1){ lastIndex = j; } } - if(endOpenSat){ - Satellite sat(_satellites[0].second.getSatelliteType(), _satellites[0].second.getIsTime(), true, active, _satellites[0].second.getHasMirror(), hidden, 0.0, 0.0, _satellites[0].second.getSteps()); - _satellites.insert(_satellites.begin() + lastIndex + 1, std::make_pair(lastNode,sat)); + Satellite sat(_satellites[0].second.getSatelliteType(), _satellites[0].second.getIsTime(), true, active, _satellites[0].second.getHasMirror(), hidden, 0.0, 0.0, _satellites[0].second.getSteps()); + _satellites.insert(_satellites.begin() + lastIndex + 1, std::make_pair(lastNode,sat)); + } else { + for(size_t j = 0; j < _satellites.size(); j++){ + if(_satellites[j].first < firstNode){ + continue; + } + if(_satellites[j].first == firstNode && !_satellites[j].second.getActive()){ + _satellites[j].second.setActive(true); + _satellites[j].second.setHidden(_satellites[j+1].second.getHidden()); + } + + } + } + } +} + +void +Pointwise::subpath_append_reorder(size_t subpath){ + std::vector<Geom::Path> path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + size_t nSubpath = 0; + size_t counter = 0; + std::vector<Geom::Path> tmp_path; + Geom::Path rev; + for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { + if (path_it->empty()){ + continue; + } + Geom::Path::const_iterator curve_it1 = path_it->begin(); + Geom::Path::const_iterator curve_endit = path_it->end_default(); + const Curve &closingline = path_it->back_closed(); + if (are_near(closingline.initialPoint(), closingline.finalPoint())) { + curve_endit = path_it->end_open(); + } + while (curve_it1 != curve_endit) { + if(nSubpath == subpath){ + std::vector<size_t> sats = findSatellites(counter,999); + for(size_t i = 0; i< sats.size(); i++){ + _satellites.push_back(std::make_pair(_pwd2.size(),_satellites[sats[i]].second)); + } + deleteSatellites(counter); + } else { + counter++; } + ++curve_it1; } + if(nSubpath == subpath){ + rev = *path_it; + } else { + tmp_path.push_back(*path_it); + } + nSubpath++; } + tmp_path.push_back(rev); + setPwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(tmp_path)),0.01)); } void Pointwise::reverse(size_t start,size_t end){ - for(size_t i = start; i < end / 2; i++){ - std::pair<size_t,Satellite> tmp = _satellites[i]; - _satellites[i] = _satellites[end - start - i - 1]; - _satellites[end - start - i - 1] = tmp; + start ++; + for(size_t i = end; i >= start; i--){ + std::vector<size_t> sats = findSatellites(i,999); + for(size_t j = 0; j< sats.size(); j++){ + _satellites.push_back(std::make_pair(_pwd2.size(),_satellites[sats[j]].second)); + } + deleteSatellites(i); } + std::vector<Geom::Path> path_in = path_from_piecewise(remove_short_cuts(_pwd2,0.1), 0.001); + size_t counter = 0; + size_t nSubpath = 0; + size_t subpath = getSubPathIndex(start); + std::vector<Geom::Path> tmp_path; + Geom::Path rev; + for (PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { + if (path_it->empty()){ + continue; + } + counter ++; + if(nSubpath == subpath){ + tmp_path.push_back(path_it->reverse()); + } else { + tmp_path.push_back(*path_it); + } + nSubpath++; + } + setPwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(tmp_path)),0.01)); } double @@ -362,6 +460,24 @@ Pointwise::len_to_rad(double A, std::pair<size_t,Geom::Satellite> sat) const return 0; } +void +Pointwise::deleteSatellites(size_t A) +{ + bool erased = false; + for (std::vector<std::pair<size_t,Satellite> >::iterator it=_satellites.begin(); it!=_satellites.end();) + { + if(it->first == A){ + it = _satellites.erase(it); + erased = true; + } else { + if(erased){ + it->first = it->first-1; + } + ++it; + } + } +} + std::vector<size_t> Pointwise::findSatellites(size_t A, long B) const { diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index 296eb6ca6..df3997492 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -76,7 +76,9 @@ class Pointwise void recalculate_for_new_pwd2(Piecewise<D2<SBasis> > A); void pwd2_append(Piecewise<D2<SBasis> > A); void pwd2_sustract(Piecewise<D2<SBasis> > A); - void set_extremes(bool endOpenSat, bool active, bool hidden, double amount = -1, double angle = -1); + void set_extremes(bool active, bool hidden, double amount = -1, double angle = -1); + void deleteSatellites(size_t A); + void subpath_append_reorder(size_t subpath); void reverse(size_t start,size_t end); void setPathInfo(); void setPathInfo(Piecewise<D2<SBasis> >); diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 2fc2027ab..0502a4192 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -59,7 +59,8 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false), ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false), helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0), - pointwise(NULL) + pointwise(NULL), + segCount(0) { registerParameter(&satellitepairarrayparam_values); registerParameter(&unit); @@ -380,43 +381,52 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } bool refresh = false; bool hide = true; - for(unsigned i = 0; i < sats.size(); i++){ - if(sats[i].second.getIsTime() != flexible){ - sats[i].second.setIsTime(flexible); - double amount = sats[i].second.getAmount(); - D2<SBasis> d2_in = pwd2_in[sats[i].first]; - if(sats[i].second.getIsTime()){ - double time = sats[i].second.toTime(amount,d2_in); - sats[i].second.setAmount(time); + for (std::vector<std::pair<size_t,Satellite> >::iterator it = sats.begin(); it != sats.end();) + { + if(it->second.getIsTime() != flexible){ + it->second.setIsTime(flexible); + double amount = it->second.getAmount(); + D2<SBasis> d2_in = pwd2_in[it->first]; + if(it->second.getIsTime()){ + double time = it->second.toTime(amount,d2_in); + it->second.setAmount(time); } else { - double size = sats[i].second.toSize(amount,d2_in); - sats[i].second.setAmount(size); + double size = it->second.toSize(amount,d2_in); + it->second.setAmount(size); } } - if(sats[i].second.getHasMirror() != mirror_knots){ - sats[i].second.setHasMirror(mirror_knots); + if(it->second.getHasMirror() != mirror_knots){ + it->second.setHasMirror(mirror_knots); refresh = true; } - if(sats[i].second.getHidden() == false){ + if(it->second.getHidden() == false){ hide = false; } - sats[i].second.setHidden(hide_knots); + it->second.setHidden(hide_knots); + if(it->second.getIsEndOpen()){ + it = sats.erase(it); + } else { + ++it; + } } if(hide != hide_knots){ refresh = true; } - pointwise = new Pointwise(pwd2_in, sats); - //mandatory call - pointwise->set_extremes(false, false, true); + + if(pointwise && c->get_segment_count() != segCount && segCount != 0){ + pointwise->recalculate_for_new_pwd2(pwd2_in); + pointwise->set_extremes(false, true, 0.0, 0.0); + segCount = c->get_segment_count(); + } else { + pointwise = new Pointwise(pwd2_in, sats); + //mandatory call + pointwise->set_extremes(false, true); + segCount = c->get_segment_count(); + } satellitepairarrayparam_values.set_pointwise(pointwise); if(refresh){ refreshKnots(); } - if(c->nodes_in_path() != sats.size()){ - pointwise->recalculate_for_new_pwd2(pwd2_in); - pointwise->set_extremes(true, false, true, 0.0, 0.0); - satellitepairarrayparam_values.set_pointwise(pointwise); - } } else { g_warning("LPE Fillet can only be applied to shapes (not groups)."); } @@ -426,8 +436,8 @@ void LPEFilletChamfer::adjustForNewPath(std::vector<Geom::Path> const &path_in) { if (!path_in.empty() && pointwise) { - pointwise->recalculate_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); - pointwise->set_extremes(true, false, true, 0.0, 0.0); + pointwise->recalculate_for_new_pwd2(remove_short_cuts(paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)),0.01)); + pointwise->set_extremes(false, true, 0.0, 0.0); satellitepairarrayparam_values.set_pointwise(pointwise); } } @@ -532,10 +542,6 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in) if(time1 <= time0){ time1 = time0; } - std::cout << counter << ":::::::::::::::::::::::::::::\n"; - std::cout << time0 << "time0\n"; - std::cout << time1 << "time1\n"; - std::cout << time2 << "time2\n"; std::vector<double> times; times.push_back(time0); times.push_back(time1); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 1bedbefa4..89d91265a 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -65,6 +65,7 @@ private: ScalarParam helper_size; Geom::Pointwise *pointwise; + double segCount; LPEFilletChamfer(const LPEFilletChamfer &); LPEFilletChamfer &operator=(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 8102edf9b..3876dc8df 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -13,6 +13,7 @@ #include "live_effects/parameter/satellitepairarray.h" #include "live_effects/effect.h" #include "sp-lpe-item.h" +#include <preferences.h> // TODO due to internal breakage in glibmm headers, // this has to be included last. #include <glibmm/i18n.h> @@ -113,7 +114,8 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) } if(mirror == true){ if(d2_prev_index){ - pos = _vector[i].second.getOpositeTime(size_out,pwd2[*d2_prev_index]); + d2 = pwd2[*d2_prev_index]; + pos = _vector[i].second.getOpositeTime(size_out,d2); if(lenght_out < size_out){ overflow = true; } @@ -196,6 +198,24 @@ void SatellitePairArrayParam::recalculate_knots() } } +void +SatellitePairArrayParam::param_transform_multiply(Geom::Affine const &postmul, + bool /*set*/) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + + if (prefs->getBool("/options/transform/rectcorners", true)) { + for (size_t i = 0; i < _vector.size(); ++i) { + if(!_vector[i].second.getIsTime() && _vector[i].second.getAmount() > 0){ + _vector[i].second.setAmount(_vector[i].second.getAmount() * ((postmul.expansionX() + postmul.expansionY()) / 2)); + } + } + param_set_and_write_new_value(_vector); + } + + // param_set_and_write_new_value( (*this) * postmul ); +} + void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, @@ -315,6 +335,7 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, } } + Geom::Point FilletChamferKnotHolderEntity::knot_get() const { diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index a85e3f83f..462f1017c 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -52,6 +52,7 @@ public: virtual bool providesKnotHolderEntities() const { return true; } + void param_transform_multiply(Geom::Affine const &postmul, bool /*set*/); void set_document_unit(Glib::ustring value_document_unit); void set_use_distance(bool use_knot_distance ); void set_unit(const gchar *abbr); |
