diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-03-14 21:06:08 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-03-14 21:06:08 +0000 |
| commit | 14b24b5d5cc3a8c72d496bea35e16e8ca47ae458 (patch) | |
| tree | d44dca5ee6c215a03c81c1c1430a95a60f2d21ec | |
| parent | update to trunk (diff) | |
| download | inkscape-14b24b5d5cc3a8c72d496bea35e16e8ca47ae458.tar.gz inkscape-14b24b5d5cc3a8c72d496bea35e16e8ca47ae458.zip | |
commit for refactoring
(bzr r13645.1.42)
| -rw-r--r-- | src/2geom/pointwise.cpp | 148 | ||||
| -rw-r--r-- | src/2geom/pointwise.h | 18 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.cpp | 27 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.h | 2 | ||||
| -rw-r--r-- | src/live_effects/parameter/satellitepairarray.cpp | 46 | ||||
| -rw-r--r-- | src/live_effects/parameter/satellitepairarray.h | 1 |
6 files changed, 209 insertions, 33 deletions
diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index 3b182916a..96a7e8644 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -63,6 +63,95 @@ Pointwise::setPwd2(Piecewise<D2<SBasis> > pwd2_in){ _pwd2 = pwd2_in; } +void +Pointwise::recalculate_for_new_pwd2(Piecewise<D2<SBasis> > A) +{ + if( _pwd2.size() > A.size()){ + new_pwd_sustract(A); + } else if ( _pwd2.size() < A.size()){ + new_pwd_append(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; + } + } else{ + std::cout << "added\n"; + satellites.push_back(std::make_pair(_satellites[i].first-counter,_satellites[i].second)); + } + } + _pwd2 = A; + _satellites = satellites; +} +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"; + 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; + } + } + } 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) { @@ -192,6 +281,49 @@ 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 { @@ -211,6 +343,22 @@ Pointwise::findClosingSatellites(unsigned int A) const 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 { diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index b6bd4c4fd..54f272a13 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -76,16 +76,14 @@ class Pointwise Piecewise<D2<SBasis> > getPwd2(); void setPwd2(Piecewise<D2<SBasis> > pwd2_in); boost::optional<Geom::D2<Geom::SBasis> > getCurveIn(std::pair<unsigned int,Satellite> sat); - Pointwise recalculate_for_new_pwd2(Piecewise<D2<SBasis> > A); - /* - Pointwise pwd2_reverse(int index); - Pointwise pwd2_append(int index); - Pointwise pwd2_prepend(int index); - Pointwise pwd2_add(int index); - Pointwise pwd2_del(int index); - Pointwise satellite_add(unsigned int index,Satellite sat); - Pointwise satellite_del(unsigned int index,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; + private: Piecewise<D2<SBasis> > _pwd2; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 36dd599d4..b94e3c429 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -58,7 +58,7 @@ 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() + pointwise(NULL) { registerParameter(&satellitepairarrayparam_values); registerParameter(&unit); @@ -400,9 +400,8 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) changed = true; refresh = true; } - bool hide = !hide_knots; - if(it->second.getHidden() != hide){ - it->second.setHidden(hide); + if(it->second.getHidden() != hide_knots){ + it->second.setHidden(hide_knots); changed = true; refresh = true; } @@ -419,6 +418,17 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } } +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"; + 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) @@ -634,15 +644,6 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in) return pathvector_out; } -void -LPEFilletChamfer::adjustForNewPath(std::vector<Geom::Path> const &path_in) -{ - if (!path_in.empty()) { - //satellitepairarrayparam_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); - } -} - - }; //namespace LivePathEffect }; /* namespace Inkscape */ diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 3d22216d4..1bedbefa4 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -39,7 +39,7 @@ public: virtual void doOnApply(SPLPEItem const *lpeItem); virtual void adjustForNewPath(std::vector<Geom::Path> const &path_in); virtual Gtk::Widget* newWidget(); - /*double len_to_rad(double A, std::pair<int,Geom::Satellite> sat);*/ + /*double len_to_rad(double A, std::pair<int,Geom::Satellite> sat);*/ void updateSatelliteType(Geom::SatelliteType satellitetype); void updateChamferSteps(); void updateAmount(); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index 0fc27153f..45f522693 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -52,6 +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"; } void SatellitePairArrayParam::set_document_unit(Glib::ustring value_document_unit) @@ -82,7 +83,7 @@ void SatellitePairArrayParam::set_helper_size(int hs) void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) { - if( last_pointwise == NULL){ + if(!last_pointwise){ return; } Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = last_pointwise->getPwd2(); @@ -90,7 +91,7 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) hp.clear(); } for (unsigned int i = 0; i < _vector.size(); ++i) { - if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ + if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ continue; } if((!_vector[i].second.getHasMirror() && mirror == true) || _vector[i].second.getAmount() == 0){ @@ -188,13 +189,24 @@ void SatellitePairArrayParam::addCanvasIndicators( hp_vec.push_back(hp); } +void SatellitePairArrayParam::recalculate_knots() +{ + if(last_pointwise){ + _vector = last_pointwise->getSatellites(); + write_to_SVG(); + } +} + void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, 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) { - if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){ + if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ continue; } if(!_vector[i].second.getHasMirror() && mirror == true){ @@ -262,10 +274,18 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } - if( _pparam->last_pointwise == NULL){ + if (!valid_index(index)) { + return; + } + + if( !_pparam->last_pointwise ){ return; } + std::pair<int,Geom::Satellite> satellite = _pparam->_vector.at(index); + if(!satellite.second.getActive() || satellite.second.getHidden()){ + return; + } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = pointwise->getPwd2(); if(_pparam->_vector.size() <= _index){ @@ -305,12 +325,21 @@ FilletChamferKnotHolderEntity::knot_get() const if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } + if (!valid_index(index)) { + return Point(infinity(), infinity()); + } std::pair<int,Geom::Satellite> satellite = _pparam->_vector.at(index); - if( _pparam->last_pointwise == NULL){ - return Geom::Point(0,0); + if(!_pparam->last_pointwise){ + return Point(infinity(), infinity()); + } + if(!satellite.second.getActive() || satellite.second.getHidden()){ + return Point(infinity(), infinity()); } 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); @@ -340,10 +369,9 @@ FilletChamferKnotHolderEntity::knot_get() const return canvas_point; } - void FilletChamferKnotHolderEntity::knot_click(guint state) { - if( _pparam->last_pointwise == NULL){ + if( !_pparam->last_pointwise){ return; } @@ -416,7 +444,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) { - if( _pparam->last_pointwise == NULL){ + if( !_pparam->last_pointwise){ return; } int index = _index; diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h index d20339ccb..9b22a386b 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitepairarray.h @@ -56,6 +56,7 @@ public: void set_use_distance(bool use_knot_distance ); void set_unit(const gchar *abbr); void set_effect_type(EffectType et); + void recalculate_knots(); virtual void updateCanvasIndicators(); virtual void updateCanvasIndicators(bool mirror); void set_pointwise(Geom::Pointwise *pointwise); |
