diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-03-01 22:23:56 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-03-01 22:23:56 +0000 |
| commit | f77b5496f69a5391bc548be95c85659539a92fe9 (patch) | |
| tree | 119950ee4b1106292d43cc1de4d3eee8f664c3b5 /src | |
| parent | adding mirror knot (diff) | |
| download | inkscape-f77b5496f69a5391bc548be95c85659539a92fe9.tar.gz inkscape-f77b5496f69a5391bc548be95c85659539a92fe9.zip | |
added mirror knots
(bzr r13645.1.26)
Diffstat (limited to 'src')
| -rw-r--r-- | src/2geom/pointwise.cpp | 35 | ||||
| -rw-r--r-- | src/2geom/pointwise.h | 2 | ||||
| -rw-r--r-- | src/2geom/satellite.cpp | 10 | ||||
| -rw-r--r-- | src/2geom/satellite.h | 26 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.cpp | 48 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.h | 1 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.cpp | 14 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.h | 4 | ||||
| -rw-r--r-- | src/live_effects/parameter/satellitepairarray.cpp | 35 |
9 files changed, 145 insertions, 30 deletions
diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp index bc468343c..3c359eddc 100644 --- a/src/2geom/pointwise.cpp +++ b/src/2geom/pointwise.cpp @@ -123,6 +123,41 @@ Pointwise::findSatellites(int A, int B) const return ret; } +std::vector<Satellite> +Pointwise::findClosingSatellites(int A, int B) 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; +} + +std::vector<Satellite> +Pointwise::findPeviousSatellites(int A, int B) const +{ + 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, B); + } + } + } + return ret; +} + } /* Local Variables: diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h index 5937264ad..c7426dc9d 100644 --- a/src/2geom/pointwise.h +++ b/src/2geom/pointwise.h @@ -67,6 +67,8 @@ class Pointwise Pointwise(Piecewise<D2<SBasis> > pwd2, std::vector<std::pair<int,Satellite> > satellites); virtual ~Pointwise(); std::vector<Satellite> findSatellites(int A, int B = -1) const; + std::vector<Satellite> findPeviousSatellites(int A, int B) const; + std::vector<Satellite> findClosingSatellites(int A, int B) const; std::vector<std::pair<int,Satellite> > getSatellites(); void setSatellites(std::vector<std::pair<int,Satellite> > sat); Piecewise<D2<SBasis> > getPwd2(); diff --git a/src/2geom/satellite.cpp b/src/2geom/satellite.cpp index 21361147c..9c253523e 100644 --- a/src/2geom/satellite.cpp +++ b/src/2geom/satellite.cpp @@ -40,8 +40,8 @@ namespace Geom { Satellite::Satellite(){}; -Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool active, bool hasMirror, bool hidden, double ammount, double angle) - : _satellitetype(satellitetype), _isTime(isTime), _active(active), _hasMirror(hasMirror), _hidden(hidden), _ammount(ammount), _angle(angle){}; +Satellite::Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double ammount, double angle) + : _satellitetype(satellitetype), _isTime(isTime), _isClosing(isClosing), _isStart(isStart), _active(active), _hasMirror(hasMirror), _hidden(hidden), _ammount(ammount), _angle(angle){}; Satellite::~Satellite() {}; @@ -98,12 +98,8 @@ Satellite::toSize(double A,Geom::D2<Geom::SBasis> d2_in) } double -Satellite::getOpositeTime(Geom::D2<Geom::SBasis> d2_in) +Satellite::getOpositeTime(double s, Geom::D2<Geom::SBasis> d2_in) { - double s = getAmmount(); - if(getIsTime()){ - s = toSize(s, d2_in); - } if(s == 0){ return 1; } diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h index c66770bb6..7581e6e34 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 active, bool hasMirror, bool hidden, double ammount, double angle); + Satellite(SatelliteType satellitetype, bool isTime, bool isClosing, bool isStart, bool active, bool hasMirror, bool hidden, double ammount, double angle); virtual ~Satellite(); @@ -65,6 +65,16 @@ class Satellite _isTime = A; } + void setIsClosing(bool A) + { + _isClosing = A; + } + + void setIsStart(bool A) + { + _isStart = A; + } + void setActive(bool A) { _active = A; @@ -105,6 +115,16 @@ class Satellite return _isTime; } + bool getIsClosing() const + { + return _isClosing; + } + + bool getIsStart() const + { + return _isStart; + } + bool getActive() const { return _active; @@ -133,7 +153,7 @@ class Satellite void setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in); Geom::Point getPosition(Geom::D2<Geom::SBasis> curve); double getTime(Geom::D2<Geom::SBasis> d2_in); - double getOpositeTime(Geom::D2<Geom::SBasis> SBasisCurve); + 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); @@ -141,6 +161,8 @@ class Satellite SatelliteType _satellitetype; bool _isTime; + bool _isClosing; + bool _isStart; 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 41c6a7090..d46d0f4ff 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -48,11 +48,13 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this), method(_("Method:"), _("Fillets methods"), "method", FMConverter, &wr, this, FM_AUTO), flexible(_("Flexible radius size (%)"), _("Flexible radius size (%)"), "flexible", &wr, this, false), + mirrorKnots(_("Mirror Knots"), _("Mirror Knots"), "mirrorKnots", &wr, this, true), pointwise() { registerParameter(&satellitepairarrayparam_values); registerParameter(&method); registerParameter(&flexible); + registerParameter(&mirrorKnots); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -90,24 +92,36 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) --curve_end; int counter = 0; while (curve_it1 != curve_endit) { - Satellite satellite(F, flexible, true, false, false, 0.0, 0.0); - Geom::NodeType nodetype; + bool isStart = false; + if(counter == 0){ + isStart = true; + } + bool isClosing = false; + if(path_it->closed() && curve_it1 == curve_end){ + isClosing = true; + } + bool active = true; + bool hidden = false; if (counter==0) { if (path_it->closed()) { - nodetype = get_nodetype(*curve_end, *curve_it1); } else { - nodetype = NODE_NONE; + active = false; } - } else { - nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); - } - if (nodetype == NODE_CUSP) { - satellites.push_back(std::make_pair(counterTotal, satellite)); } + Satellite satellite(F, flexible, isClosing, isStart, active, mirrorKnots, hidden, 0.0, 0.0); + satellites.push_back(std::make_pair(counterTotal, satellite)); ++curve_it1; counter++; counterTotal++; } + if (!path_it->closed()){ + bool active = false; + bool isClosing = false; + bool isStart = false; + bool hidden = false; + Satellite satellite(F, flexible, isClosing, isStart, active, mirrorKnots, hidden, 0.0, 0.0); + satellites.push_back(std::make_pair(counterTotal, satellite)); + } } pointwise = new Pointwise( pwd2_in,satellites); satellitepairarrayparam_values.param_set_and_write_new_value(satellites); @@ -152,6 +166,10 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) } changed = true; } + if(it->second.getHasMirror() != mirrorKnots){ + it->second.setHasMirror(mirrorKnots); + changed = true; + } } if(changed){ pointwise->setSatellites(satellites); @@ -218,12 +236,16 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in) if(first == counter){ satVector = pointwise->findSatellites(first,1); if(satVector.size()>0){ - time0 = satVector[0].getTime(curve_it2Fixed->toSBasis()); + time0 = satVector[0].getTime(path_it->begin()->duplicate()->toSBasis()); } } bool last = curve_it2 == curve_endit; - double time1 = sat.getOpositeTime((*curve_it1).toSBasis()); + double s = sat.getAmmount(); + if(sat.getIsTime()){ + s = sat.toSize(s, curve_it2Fixed->toSBasis()); + } + double time1 = sat.getOpositeTime(s,(*curve_it1).toSBasis()); double time2 = sat.getTime(curve_it2Fixed->toSBasis()); if(time1 <= time0){ time1 = time0; @@ -249,7 +271,7 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in) endArcPoint = curve_it2Fixed->pointAt(times[2]-gapHelper); } if(times[1] == times[0]){ - startArcPoint = knotCurve1->pointAt(1-gapHelper); + startArcPoint = curve_it1->pointAt(times[0]+gapHelper); } double k1 = distance(startArcPoint, curve_it1->finalPoint()) * K; double k2 = distance(endArcPoint, curve_it2Fixed->initialPoint()) * K; @@ -289,7 +311,7 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in) endArcPoint = curve_it2Fixed->pointAt(times[2]); } if(times[1] == times[0]){ - startArcPoint = knotCurve1->pointAt(1); + startArcPoint = curve_it1->pointAt(times[0]); } Line const x_line(Geom::Point(0,0),Geom::Point(1,0)); Line const angled_line(startArcPoint,endArcPoint); diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index f5c4f14ea..149a2d743 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -43,6 +43,7 @@ public: private: EnumParam<FilletMethod> method; BoolParam flexible; + BoolParam mirrorKnots; Geom::Pointwise *pointwise; LPEFilletChamfer(const LPEFilletChamfer &); diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 2c3d823a5..c00cdd8da 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -54,15 +54,17 @@ sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ return 0; } gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray[6] && !strarray[7]){ + if(strarray[8] && !strarray[9]){ sat->setSatelliteType(strarray[0]); sat->setIsTime(strncmp(strarray[1],"1",1) == 0); - sat->setActive(strncmp(strarray[2],"1",1) == 0); - sat->setHasMirror(strncmp(strarray[3],"1",1) == 0); - sat->setHidden(strncmp(strarray[4],"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); double ammount,angle; - sp_svg_number_read_d(strarray[5], &ammount); - sp_svg_number_read_d(strarray[6], &angle); + sp_svg_number_read_d(strarray[7], &ammount); + sp_svg_number_read_d(strarray[8], &angle); sat->setAmmount(ammount); sat->setAngle(angle); g_strfreev (strarray); diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 1a5823199..0be155f50 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -119,6 +119,10 @@ protected: str << "*"; str << nVector.second.getIsTime(); str << "*"; + str << nVector.second.getIsClosing(); + str << "*"; + str << nVector.second.getIsStart(); + str << "*"; str << nVector.second.getActive(); str << "*"; str << nVector.second.getHasMirror(); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp index e6f0c03f9..7a35df28f 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitepairarray.cpp @@ -54,7 +54,9 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { for (unsigned int i = 0; i < _vector.size(); ++i) { - addKnotHolderEntitieMirrored(knotholder, desktop, item, i); + if(_vector[i].second.getHasMirror()){ + addKnotHolderEntitieMirrored(knotholder, desktop, item, i); + } const gchar *tip; tip = _("<b>Fillet</b>: <b>Ctrl+Click</b> toggle type, " "<b>Shift+Click</b> open dialog, " @@ -105,10 +107,20 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p, boost::optional<Geom::D2<Geom::SBasis> > d2_in = pointwise->getCurveIn(satellite); if(d2_in){ 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); + } + if(timeStart > mirrorTime){ + mirrorTime = timeStart; + } 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]); + std::cout << time << "time\n"; s = pwd2[satellite.first].valueAt(time); + std::cout << s << "s\n"; satellite.second.setPosition(s,pwd2[satellite.first]); } } else { @@ -136,7 +148,26 @@ SatellitePairArrayParamKnotHolderEntity::knot_get() const tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); boost::optional<Geom::D2<Geom::SBasis> > d2_in = pointwise->getCurveIn(satellite); if(d2_in){ - tmpPoint = (*d2_in).valueAt(satellite.second.getOpositeTime(*d2_in)); + double s = satellite.second.getAmmount(); + if(satellite.second.getIsTime()){ + s = satellite.second.toSize(s, pwd2[satellite.first]); + } + double t = satellite.second.getOpositeTime(s,*d2_in); + if(t > 1){ + t = 1; + } + if(t < 0){ + t = 0; + } + double timeStart = 0; + std::vector<Satellite> satVector = pointwise->findPeviousSatellites(satellite.first,1); + if(satVector.size()>0){ + timeStart = satVector[0].getTime(*d2_in); + } + if(timeStart > t){ + t = timeStart; + } + tmpPoint = (*d2_in).valueAt(t); } } else { tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); |
