From 00d08a0f4bca11e775bbacf3d512676a0493c1a3 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 1 Mar 2015 01:18:02 +0100 Subject: adding mirror knot (bzr r13645.1.25) --- src/live_effects/parameter/satellitepairarray.cpp | 62 ++++++++++++++++++++--- 1 file changed, 56 insertions(+), 6 deletions(-) (limited to 'src/live_effects/parameter/satellitepairarray.cpp') diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index bb72830d6..e6f0c03f9 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -44,10 +44,9 @@ void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, knot_color = color; } -void SatellitePairArrayParam::set_pwd2( - Piecewise > const &pwd2_in) +void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) { - last_pwd2 = pwd2_in; + last_pointwise = pointwise; } void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, @@ -55,6 +54,7 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { for (unsigned int i = 0; i < _vector.size(); ++i) { + addKnotHolderEntitieMirrored(knotholder, desktop, item, i); const gchar *tip; tip = _("Fillet: Ctrl+Click toggle type, " "Shift+Click open dialog, " @@ -67,6 +67,19 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, } } +void SatellitePairArrayParam::addKnotHolderEntitieMirrored(KnotHolder *knotholder, + SPDesktop *desktop, + SPItem *item, int i) +{ + const gchar *tip; + tip = _("Mirror ppp"); + SatellitePairArrayParamKnotHolderEntity *e = + new SatellitePairArrayParamKnotHolderEntity(this, i + _vector.size()); + e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), + knot_shape, knot_mode, knot_color); + knotholder->add(e); +} + SatellitePairArrayParamKnotHolderEntity::SatellitePairArrayParamKnotHolderEntity(SatellitePairArrayParam *p, unsigned int index) : _pparam(p), @@ -80,8 +93,28 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, Point const &/*origin*/, guint state) { - Geom::Point const s = snap_knot_position(p, state); - _pparam->_vector.at(_index).second.setPosition(s,_pparam->last_pwd2[_pparam->_vector.at(_index).first]); + Geom::Point s = snap_knot_position(p, state); + int index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + std::pair satellite = _pparam->_vector.at(index); + Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + if(_pparam->_vector.size() <= _index){ + boost::optional > d2_in = pointwise->getCurveIn(satellite); + if(d2_in){ + double mirrorTime = Geom::nearest_point(s, *d2_in); + double size = satellite.second.toSize(mirrorTime, *d2_in); + double lenght = Geom::length(*d2_in, Geom::EPSILON) - size; + double time = satellite.second.toTime(lenght,pwd2[satellite.first]); + s = pwd2[satellite.first].valueAt(time); + satellite.second.setPosition(s,pwd2[satellite.first]); + } + } else { + satellite.second.setPosition(s,pwd2[satellite.first]); + } + _pparam->_vector.at(index) = satellite; SPLPEItem * splpeitem = dynamic_cast(item); if(splpeitem){ sp_lpe_item_update_patheffect(splpeitem, false, false); @@ -91,7 +124,24 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, Geom::Point SatellitePairArrayParamKnotHolderEntity::knot_get() const { - Geom::Point const canvas_point = _pparam->_vector.at(_index).second.getPosition(_pparam->last_pwd2[_pparam->_vector.at(_index).first]); + Geom::Point tmpPoint; + int index = _index; + if( _index >= _pparam->_vector.size()){ + index = _index-_pparam->_vector.size(); + } + std::pair satellite = _pparam->_vector.at(index); + Geom::Pointwise* pointwise = _pparam->last_pointwise; + Geom::Piecewise > pwd2 = pointwise->getPwd2(); + if( _index >= _pparam->_vector.size()){ + tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); + boost::optional > d2_in = pointwise->getCurveIn(satellite); + if(d2_in){ + tmpPoint = (*d2_in).valueAt(satellite.second.getOpositeTime(*d2_in)); + } + } else { + tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); + } + Geom::Point const canvas_point = tmpPoint; return canvas_point; } -- cgit v1.2.3