diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-04-01 02:13:16 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-04-01 02:13:16 +0000 |
| commit | dff3aa428ff050c2cce501f646977ddad921feca (patch) | |
| tree | 3152c9b571095e1db57af2522129d278b5f4ce39 /src/live_effects | |
| parent | removed code comments (diff) | |
| download | inkscape-dff3aa428ff050c2cce501f646977ddad921feca.tar.gz inkscape-dff3aa428ff050c2cce501f646977ddad921feca.zip | |
Move 2Geom work to a intermediate positon -helper-
Removed dependency to helper/geom.h
Now use a simple vector, not a vector of pairs of size_t and Satellite
Getters and setters on Satellite removed
Update store parameter to a more friendly string, like powerstroke
Todo:
Documentation and Fix coding style.
(bzr r13645.1.63)
Diffstat (limited to 'src/live_effects')
| -rw-r--r-- | src/live_effects/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.cpp | 173 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.h | 9 | ||||
| -rw-r--r-- | src/live_effects/parameter/Makefile_insert | 4 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.cpp | 77 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.h | 38 | ||||
| -rw-r--r-- | src/live_effects/parameter/satellitearray.cpp (renamed from src/live_effects/parameter/satellitepairarray.cpp) | 159 | ||||
| -rw-r--r-- | src/live_effects/parameter/satellitearray.h (renamed from src/live_effects/parameter/satellitepairarray.h) | 18 |
8 files changed, 240 insertions, 242 deletions
diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 3af27a220..7bafb356d 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -62,7 +62,7 @@ set(live_effects_SRC parameter/path-reference.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp - parameter/satellitepairarray.cpp + parameter/satellitearray.cpp parameter/random.cpp parameter/text.cpp paramter/transformedpoint.cpp @@ -138,7 +138,7 @@ set(live_effects_SRC parameter/originalpatharray.h parameter/point.h parameter/powerstrokepointarray.h - parameter/satellitepairarray.h + parameter/satellitearray.h parameter/random.h parameter/text.h parameter/togglebutton.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 6775fa000..54b2fb52f 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -16,13 +16,15 @@ #include "live_effects/lpe-fillet-chamfer.h" -#include <2geom/satellite.h> -#include <2geom/satellite-enum.h> #include "helper/geom.h" #include "display/curve.h" #include "helper/geom-curves.h" +#include "helper/geom-satellite.h" +#include "helper/geom-satellite-enum.h" +#include "helper/geom-pathinfo.h" #include <2geom/svg-elliptical-arc.h> #include "knotholder.h" +#include <boost/optional.hpp> // TODO due to internal breakage in glibmm headers, this must be last: #include <glibmm/i18n.h> @@ -40,7 +42,7 @@ FMConverter(FilletMethodData, FM_END); LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - satellitepairarrayparam_values(_("pair_array_param"), _("pair_array_param"), "satellitepairarrayparam_values", &wr, this), + satellitearrayparam_values(_("pair_array_param"), _("pair_array_param"), "satellitearrayparam_values", &wr, this), unit(_("Unit:"), _("Unit"), "unit", &wr, this), method(_("Method:"), _("Methods to calculate the fillet or chamfer"), "method", FMConverter, &wr, this, FM_AUTO), radius(_("Radius (unit or %):"), _("Radius, in unit or %"), "radius", &wr, this, 0.), @@ -55,7 +57,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : pointwise(NULL), segCount(0) { - registerParameter(&satellitepairarrayparam_values); + registerParameter(&satellitearrayparam_values); registerParameter(&unit); registerParameter(&method); registerParameter(&radius); @@ -91,7 +93,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) Piecewise<D2<SBasis> > pwd2_in = paths_to_pw(original_pathv); pwd2_in = remove_short_cuts(pwd2_in, 0.01); int counterTotal = 0; - std::vector<std::pair<size_t,Geom::Satellite> > satellites; + std::vector<Geom::Satellite> satellites; for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()){ continue; @@ -121,7 +123,6 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) item->removeCurrentPathEffect(false); return; } - bool isEndOpen = false; bool active = true; bool hidden = false; if (counter==0) { @@ -129,22 +130,15 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) active = false; } } - Satellite satellite(F, flexible, isEndOpen, active, mirror_knots, hidden, 0.0, 0.0, steps); - satellites.push_back(std::make_pair(counterTotal, satellite)); + Satellite satellite(F, flexible, active, mirror_knots, hidden, 0.0, 0.0, steps); + satellites.push_back(satellite); ++curve_it1; counter++; counterTotal++; } - if (!path_it->closed()){ - bool active = false; - bool isEndOpen = true; - bool hidden = true; - 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.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast<SPLPEItem*>(lpeItem); @@ -253,8 +247,8 @@ void LPEFilletChamfer::inverseChamfer() void LPEFilletChamfer::refreshKnots() { - if(satellitepairarrayparam_values.knoth){ - satellitepairarrayparam_values.knoth->update_knots(); + if(satellitearrayparam_values.knoth){ + satellitearrayparam_values.knoth->update_knots(); } } @@ -266,81 +260,85 @@ void LPEFilletChamfer::updateAmount() } else { power = radius/100; } - std::vector<std::pair<size_t,Geom::Satellite> > satellites = pointwise->getSatellites(); + std::vector<Geom::Satellite> satellites = pointwise->getSatellites(); Piecewise<D2<SBasis> > pwd2 = pointwise->getPwd2(); - for (std::vector<std::pair<size_t,Geom::Satellite> >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(!pointwise->getIsClosed(it->first) && pointwise->getFirst(it->first) == it->first){ - it->second.setAmount(0); + Pathinfo pathInfo(pwd2); + for (std::vector<Geom::Satellite>::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(!pathInfo.getIsClosed(it - satellites.begin()) && pathInfo.getFirst(it - satellites.begin()) == (unsigned)(it - satellites.begin())){ + it->amount = 0; continue; } - if(ignore_radius_0 && it->second.getAmount() == 0){ + if(ignore_radius_0 && it->amount == 0){ continue; } - + boost::optional<size_t> prev = pathInfo.getPrevious(it - satellites.begin()); + boost::optional<Geom::D2<Geom::SBasis> > prevPwd2 = boost::none; + boost::optional<Geom::Satellite > prevSat = boost::none; + if(prev){ + prevPwd2 = pwd2[*prev]; + prevSat = satellites[*prev]; + } if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it->first); + Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); if(isNodePointSelected(satPoint)){ if(!use_knot_distance && !flexible){ - it->second.setAmount(pointwise->rad_to_len(power,*it)); + it->amount = it->rad_to_len(power, prevPwd2, pwd2[it - satellites.begin()], prevSat); } else { - it->second.setAmount(power); + it->amount = power; } } } else { if(!use_knot_distance && !flexible){ - it->second.setAmount(pointwise->rad_to_len(power,*it)); + it->amount = it->rad_to_len(power, prevPwd2, pwd2[it - satellites.begin()], prevSat); } else { - it->second.setAmount(power); + it->amount = power; } } - if(it->second.getIsEndOpen()){ - it->second.setAmount(0); - } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::updateChamferSteps() { - std::vector<std::pair<size_t,Geom::Satellite> > satellites = pointwise->getSatellites(); + std::vector<Geom::Satellite> satellites = pointwise->getSatellites(); Piecewise<D2<SBasis> > pwd2 = pointwise->getPwd2(); - for (std::vector<std::pair<size_t,Geom::Satellite> >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->second.getAmount() == 0){ + for (std::vector<Geom::Satellite>::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(ignore_radius_0 && it->amount == 0){ continue; } if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it->first); + Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); if(isNodePointSelected(satPoint)){ - it->second.setSteps(chamfer_steps); + it->steps = chamfer_steps; } } else { - it->second.setSteps(chamfer_steps); + it->steps = chamfer_steps; } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::updateSatelliteType(Geom::SatelliteType satellitetype) { - std::vector<std::pair<size_t,Geom::Satellite> > satellites = pointwise->getSatellites(); + std::vector<Geom::Satellite> satellites = pointwise->getSatellites(); Piecewise<D2<SBasis> > pwd2 = pointwise->getPwd2(); - for (std::vector<std::pair<size_t,Geom::Satellite> >::iterator it = satellites.begin(); it != satellites.end(); ++it) { - if(ignore_radius_0 && it->second.getAmount() == 0){ + for (std::vector<Geom::Satellite>::iterator it = satellites.begin(); it != satellites.end(); ++it) { + if(ignore_radius_0 && it->amount == 0){ continue; } if(only_selected){ - Geom::Point satPoint = pwd2.valueAt(it->first); + Geom::Point satPoint = pwd2.valueAt(it - satellites.begin()); if(isNodePointSelected(satPoint)){ - it->second.setSatelliteType(satellitetype); + it->satelliteType = satellitetype; } } else { - it->second.setSatelliteType(satellitetype); + it->satelliteType = satellitetype; } } pointwise->setSatellites(satellites); - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); } void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) @@ -354,51 +352,47 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) c = path->get_original_curve(); } //fillet chamfer specific calls - satellitepairarrayparam_values.set_document_unit(defaultUnit); - satellitepairarrayparam_values.set_use_distance(use_knot_distance); - satellitepairarrayparam_values.set_unit(unit.get_abbreviation()); + satellitearrayparam_values.set_document_unit(defaultUnit); + satellitearrayparam_values.set_use_distance(use_knot_distance); + satellitearrayparam_values.set_unit(unit.get_abbreviation()); //mandatory call - satellitepairarrayparam_values.set_effect_type(this->effectType()); + satellitearrayparam_values.set_effect_type(this->effectType()); 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<size_t,Geom::Satellite> > sats = satellitepairarrayparam_values.data(); + std::vector<Geom::Satellite> sats = satellitearrayparam_values.data(); //optional call if(hide_knots){ - satellitepairarrayparam_values.set_helper_size(0); + satellitearrayparam_values.set_helper_size(0); } else { - satellitepairarrayparam_values.set_helper_size(helper_size); + satellitearrayparam_values.set_helper_size(helper_size); } bool refresh = false; bool hide = true; - for (std::vector<std::pair<size_t,Satellite> >::iterator it = sats.begin(); it != sats.end();) + for (std::vector<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); + if(it->isTime != flexible){ + it->isTime = flexible; + double amount = it->amount; + D2<SBasis> d2_in = pwd2_in[it - sats.begin()]; + if(it->isTime){ + double time = it->toTime(amount,d2_in); + it->amount = time; } else { - double size = it->second.toSize(amount,d2_in); - it->second.setAmount(size); + double size = it->toSize(amount,d2_in); + it->amount = size; } } - if(it->second.getHasMirror() != mirror_knots){ - it->second.setHasMirror(mirror_knots); + if(it->hasMirror != mirror_knots){ + it->hasMirror = mirror_knots; refresh = true; } - if(it->second.getHidden() == false){ + if(it->hidden == false){ hide = false; } - it->second.setHidden(hide_knots); - if(it->second.getIsEndOpen()){ - it = sats.erase(it); - } else { - ++it; - } + it->hidden = hide_knots; + ++it; } if(hide != hide_knots){ refresh = true; @@ -414,7 +408,7 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem) pointwise->set_extremes(false, true); segCount = c->get_segment_count(); } - satellitepairarrayparam_values.set_pointwise(pointwise); + satellitearrayparam_values.set_pointwise(pointwise); if(refresh){ refreshKnots(); } @@ -429,7 +423,7 @@ LPEFilletChamfer::adjustForNewPath(std::vector<Geom::Path> const &path_in) if (!path_in.empty() && pointwise) { 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); + satellitearrayparam_values.set_pointwise(pointwise); } } @@ -472,20 +466,19 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in) size_t counterCurves = 0; size_t first = counter; double time0 = 0; + std::vector<Geom::Satellite> sats = pointwise->getSatellites(); while (curve_it1 != curve_endit) { if((*curve_it1).isDegenerate() || (*curve_it1).isDegenerate()){ g_warning("LPE Fillet not handle degenerate curves."); return path_in; } - std::vector<size_t> satIndexes; Satellite satellite; Curve *curve_it2Fixed = path_it->begin()->duplicate(); if(!path_it->closed()){ if(curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); - satIndexes = pointwise->findSatellites(counter+1,1); - if(satIndexes.size()>0){ - satellite = pointwise->getSatellites()[satIndexes[0]].second; + if(sats.size()> counter+1 ){ + satellite = sats[counter+1]; } } else { if(time0 != 1){ @@ -501,21 +494,19 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in) } else { if(curve_it2 != curve_endit){ curve_it2Fixed = (*curve_it2).duplicate(); - satIndexes = pointwise->findSatellites(counter+1,1); - if(satIndexes.size()>0){ - satellite = pointwise->getSatellites()[satIndexes[0]].second; + if(sats.size()> counter+1 ){ + satellite = sats[counter+1]; } + } else { - satIndexes = pointwise->findSatellites(first,1); - if(satIndexes.size()>0){ - satellite = pointwise->getSatellites()[satIndexes[0]].second; + if(sats.size()> first ){ + satellite = sats[first]; } } } if(first == counter){ - satIndexes = pointwise->findSatellites(first,1); - if(satIndexes.size()>0 && pointwise->getSatellites()[satIndexes[0]].second.getActive()){ - time0 = pointwise->getSatellites()[satIndexes[0]].second.getTime(path_it->begin()->duplicate()->toSBasis()); + if(sats.size() > first && sats[first].active){ + time0 = sats[first].getTime(path_it->begin()->duplicate()->toSBasis()); } else { time0 = 0; } @@ -525,7 +516,7 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in) double s = satellite.getSize(curve_it2Fixed->toSBasis()); double time1 = satellite.getOpositeTime(s,(*curve_it1).toSBasis()); double time2 = satellite.getTime(curve_it2Fixed->toSBasis()); - if(!satellite.getActive()){ + if(!satellite.active){ time1 = 1; time2 = 0; } @@ -604,8 +595,8 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in) path_out.append(*knotCurve1); } } - SatelliteType type = satellite.getSatelliteType(); - size_t steps = satellite.getSteps(); + SatelliteType type = satellite.satelliteType; + size_t steps = satellite.steps; if(steps < 1){ steps = 1; } diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index 89d91265a..e56200a17 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -14,11 +14,12 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ + #include "live_effects/parameter/enum.h" #include "live_effects/parameter/unit.h" -#include "2geom/pointwise.h" -#include "live_effects/parameter/satellitepairarray.h" +#include "live_effects/parameter/satellitearray.h" #include "live_effects/effect.h" +#include "helper/geom-pointwise.h" namespace Inkscape { namespace LivePathEffect { @@ -39,7 +40,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);*/ + void updateSatelliteType(Geom::SatelliteType satellitetype); void updateChamferSteps(); void updateAmount(); @@ -49,7 +50,7 @@ public: void fillet(); void inverseFillet(); - SatellitePairArrayParam satellitepairarrayparam_values; + SatelliteArrayParam satellitearrayparam_values; private: UnitParam unit; diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index 74b499fa2..9a0ebe235 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -22,8 +22,8 @@ ink_common_sources += \ live_effects/parameter/originalpatharray.h \ live_effects/parameter/powerstrokepointarray.cpp \ live_effects/parameter/powerstrokepointarray.h \ - live_effects/parameter/satellitepairarray.cpp \ - live_effects/parameter/satellitepairarray.h \ + live_effects/parameter/satellitearray.cpp \ + live_effects/parameter/satellitearray.h \ live_effects/parameter/text.cpp \ live_effects/parameter/text.h \ live_effects/parameter/transformedpoint.cpp \ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index 33cb53f4e..c8ee63fec 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -5,9 +5,7 @@ */ #include "live_effects/parameter/array.h" - #include "helper-fns.h" - #include <2geom/coord.h> #include <2geom/point.h> @@ -15,6 +13,35 @@ namespace Inkscape { namespace LivePathEffect { +//TODO: move maybe to svg-lenght.cpp +unsigned int +sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ + if (!str) { + return 0; + } + gchar ** strarray = g_strsplit(str, ",", 8); + if(strarray[7] && !strarray[8]){ + sat->setSatelliteType(g_strstrip(strarray[0])); + sat->isTime = strncmp(strarray[1],"1",1) == 0; + sat->active = strncmp(strarray[2],"1",1) == 0; + sat->hasMirror = strncmp(strarray[3],"1",1) == 0; + sat->hidden = strncmp(strarray[4],"1",1) == 0; + double amount,angle; + float stepsTmp; + sp_svg_number_read_d(strarray[5], &amount); + sp_svg_number_read_d(strarray[6], &angle); + sp_svg_number_read_f(strarray[7], &stepsTmp); + unsigned int steps = (unsigned int)stepsTmp; + sat->amount = amount; + sat->angle = angle; + sat->steps = steps; + g_strfreev (strarray); + return 1; + } + g_strfreev (strarray); + return 0; +} + template <> double ArrayParam<double>::readsvg(const gchar * str) @@ -47,51 +74,17 @@ ArrayParam<Geom::Point>::readsvg(const gchar * str) } return Geom::Point(Geom::infinity(),Geom::infinity()); } -//TODO: move maybe to svg-lenght.cpp -unsigned int -sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ - if (!str) { - return 0; - } - gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray[8] && !strarray[9]){ - sat->setSatelliteType(strarray[0]); - sat->setIsTime(strncmp(strarray[1],"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[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); - sat->setSteps(steps); - g_strfreev (strarray); - return 1; - } - g_strfreev (strarray); - return 0; -} template <> -std::pair<size_t, Geom::Satellite> -ArrayParam<std::pair<size_t, Geom::Satellite> >::readsvg(const gchar * str) +Geom::Satellite +ArrayParam<Geom::Satellite >::readsvg(const gchar * str) { - gchar ** strarray = g_strsplit(str, ",", 2); - double index; - std::pair<size_t, Geom::Satellite> result; - unsigned int success = (int)sp_svg_number_read_d(strarray[0], &index); Geom::Satellite sat; - success += sp_svg_satellite_read_d(strarray[1], &sat); - g_strfreev (strarray); - if (success == 2) { - return std::make_pair((size_t)index, sat); + if (sp_svg_satellite_read_d(str, &sat)) { + return sat; } - return std::make_pair((size_t)0,sat); + Geom::Satellite satellite(Geom::F, true, false, false, true, 0.0, 0.0, 0); + return satellite; } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index 4fb053dbb..25e479304 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -15,8 +15,8 @@ #include "live_effects/parameter/parameter.h" -#include <2geom/satellite.h> -#include <2geom/satellite-enum.h> +#include "helper/geom-satellite.h" +#include "helper/geom-satellite-enum.h" #include "svg/svg.h" #include "svg/stringstream.h" @@ -111,26 +111,22 @@ protected: str << nVector; } - void writesvgData(SVGOStringStream &str, std::pair<size_t, Geom::Satellite> const &nVector) const { - str << nVector.first; + void writesvgData(SVGOStringStream &str, Geom::Satellite const &nVector) const { + str << nVector.getSatelliteTypeGchar(); str << ","; - str << nVector.second.getSatelliteTypeGchar(); - str << "*"; - str << nVector.second.getIsTime(); - str << "*"; - str << nVector.second.getIsEndOpen(); - str << "*"; - str << nVector.second.getActive(); - str << "*"; - str << nVector.second.getHasMirror(); - str << "*"; - str << nVector.second.getHidden(); - str << "*"; - str << nVector.second.getAmount(); - str << "*"; - str << nVector.second.getAngle(); - str << "*"; - str << nVector.second.getSteps(); + str << nVector.isTime; + str << ","; + str << nVector.active; + str << ","; + str << nVector.hasMirror; + str << ","; + str << nVector.hidden; + str << ","; + str << nVector.amount; + str << ","; + str << nVector.angle; + str << ","; + str << nVector.steps; } StorageType readsvg(const gchar * str); diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitearray.cpp index 461a6b54e..24a491b4b 100644 --- a/src/live_effects/parameter/satellitepairarray.cpp +++ b/src/live_effects/parameter/satellitearray.cpp @@ -10,10 +10,11 @@ #include "knotholder.h" #include "ui/dialog/lpe-fillet-chamfer-properties.h" -#include "live_effects/parameter/satellitepairarray.h" +#include "live_effects/parameter/satellitearray.h" #include "live_effects/effect.h" #include "sp-lpe-item.h" #include <preferences.h> +#include <boost/optional.hpp> // TODO due to internal breakage in glibmm headers, // this has to be included last. #include <glibmm/i18n.h> @@ -25,11 +26,11 @@ namespace Inkscape { namespace LivePathEffect { -SatellitePairArrayParam::SatellitePairArrayParam( +SatelliteArrayParam::SatelliteArrayParam( const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) - : ArrayParam<std::pair<size_t,Geom::Satellite> >(label, tip, key, wr, effect, 0), + : ArrayParam<Geom::Satellite>(label, tip, key, wr, effect, 0), knoth(NULL) { knot_shape = SP_KNOT_SHAPE_DIAMOND; @@ -41,9 +42,9 @@ SatellitePairArrayParam::SatellitePairArrayParam( last_pointwise = NULL; } -SatellitePairArrayParam::~SatellitePairArrayParam() {} +SatelliteArrayParam::~SatelliteArrayParam() {} -void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, +void SatelliteArrayParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color) { @@ -52,77 +53,78 @@ void SatellitePairArrayParam::set_oncanvas_looks(SPKnotShapeType shape, knot_color = color; } -void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise) +void SatelliteArrayParam::set_pointwise(Geom::Pointwise *pointwise) { last_pointwise = pointwise; param_set_and_write_new_value(last_pointwise->getSatellites()); } -void SatellitePairArrayParam::set_document_unit(Glib::ustring value_document_unit) +void SatelliteArrayParam::set_document_unit(Glib::ustring value_document_unit) { documentUnit = value_document_unit; } -void SatellitePairArrayParam::set_use_distance(bool use_knot_distance ) +void SatelliteArrayParam::set_use_distance(bool use_knot_distance ) { use_distance = use_knot_distance; } -void SatellitePairArrayParam::set_unit(const gchar *abbr) +void SatelliteArrayParam::set_unit(const gchar *abbr) { unit = abbr; } -void SatellitePairArrayParam::set_effect_type(EffectType et) +void SatelliteArrayParam::set_effect_type(EffectType et) { _effectType = et; } -void SatellitePairArrayParam::set_helper_size(int hs) +void SatelliteArrayParam::set_helper_size(int hs) { helper_size = hs; updateCanvasIndicators(); } -void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) +void SatelliteArrayParam::updateCanvasIndicators(bool mirror) { if(!last_pointwise){ return; } Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = last_pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); if( mirror == true){ hp.clear(); } for (size_t i = 0; i < _vector.size(); ++i) { - if(!_vector[i].second.getActive() || _vector[i].second.getHidden()){ + if(!_vector[i].active || _vector[i].hidden){ continue; } - if((!_vector[i].second.getHasMirror() && mirror == true) || _vector[i].second.getAmount() == 0){ + if((!_vector[i].hasMirror && mirror == true) || _vector[i].amount == 0){ continue; } double pos = 0; - if(pwd2.size() <= (unsigned)_vector[i].first){ + if(pwd2.size() <= i){ break; } - Geom::D2<Geom::SBasis> d2 = pwd2[_vector[i].first]; + Geom::D2<Geom::SBasis> d2 = pwd2[i]; bool overflow = false; - double size_out = _vector[i].second.getSize(pwd2[_vector[i].first]); - double lenght_out = Geom::length(pwd2[_vector[i].first], Geom::EPSILON); + double size_out = _vector[i].getSize(pwd2[i]); + double lenght_out = Geom::length(pwd2[i], Geom::EPSILON); double lenght_in = 0; - boost::optional<size_t> d2_prev_index = last_pointwise->getPrevious(_vector[i].first); + boost::optional<size_t> d2_prev_index = pathInfo.getPrevious(i); if(d2_prev_index){ lenght_in = Geom::length(pwd2[*d2_prev_index], Geom::EPSILON); } if(mirror == true){ if(d2_prev_index){ d2 = pwd2[*d2_prev_index]; - pos = _vector[i].second.getOpositeTime(size_out,d2); + pos = _vector[i].getOpositeTime(size_out,d2); if(lenght_out < size_out){ overflow = true; } } } else { - pos = _vector[i].second.getTime(d2); + pos = _vector[i].getTime(d2); if(lenght_in < size_out){ overflow = true; } @@ -181,18 +183,18 @@ void SatellitePairArrayParam::updateCanvasIndicators(bool mirror) updateCanvasIndicators(false); } } -void SatellitePairArrayParam::updateCanvasIndicators() +void SatelliteArrayParam::updateCanvasIndicators() { updateCanvasIndicators(true); } -void SatellitePairArrayParam::addCanvasIndicators( +void SatelliteArrayParam::addCanvasIndicators( SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec) { hp_vec.push_back(hp); } -void SatellitePairArrayParam::recalculate_knots() +void SatelliteArrayParam::recalculate_knots() { if(last_pointwise){ _vector = last_pointwise->getSatellites(); @@ -200,15 +202,15 @@ void SatellitePairArrayParam::recalculate_knots() } void -SatellitePairArrayParam::param_transform_multiply(Geom::Affine const &postmul, +SatelliteArrayParam::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)); + if(!_vector[i].isTime && _vector[i].amount > 0){ + _vector[i].amount = _vector[i].amount * ((postmul.expansionX() + postmul.expansionY()) / 2); } } param_set_and_write_new_value(_vector); @@ -217,7 +219,7 @@ SatellitePairArrayParam::param_transform_multiply(Geom::Affine const &postmul, // param_set_and_write_new_value( (*this) * postmul ); } -void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, +void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, bool mirror) @@ -228,14 +230,14 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, if( mirror == true){ iPlus = i + _vector.size(); } - if(!_vector[i].second.getActive()){ + if(!_vector[i].active){ continue; } - if(!_vector[i].second.getHasMirror() && mirror == true){ + if(!_vector[i].hasMirror && mirror == true){ continue; } using namespace Geom; - SatelliteType type = _vector[i].second.getSatelliteType(); + SatelliteType type = _vector[i].satelliteType; //IF is for filletChamfer effect... if(_effectType == FILLET_CHAMFER){ const gchar *tip; @@ -268,7 +270,7 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, } } -void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, +void SatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { @@ -276,7 +278,7 @@ void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder, addKnotHolderEntities(knotholder, desktop, item, true); } -FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index) +FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index) : _pparam(p), _index(index) { @@ -299,34 +301,33 @@ void FilletChamferKnotHolderEntity::knot_set(Point const &p, return; } - std::pair<int,Geom::Satellite> satellite = _pparam->_vector.at(index); - if(!satellite.second.getActive() || satellite.second.getHidden()){ + Geom::Satellite satellite = _pparam->_vector.at(index); + if(!satellite.active || satellite.hidden){ return; } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); if(_pparam->_vector.size() <= _index){ - boost::optional<size_t> d2_prev_index = pointwise->getPrevious(satellite.first); + boost::optional<size_t> d2_prev_index = pathInfo.getPrevious(index); 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<size_t> satIndexes = pointwise->findPeviousSatellites(satellite.first,1); - if(satIndexes.size()>0){ - timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); - } + std::vector<Geom::Satellite> sats = pointwise->getSatellites(); + timeStart = sats[*d2_prev_index].getTime(d2_in); if(timeStart > mirrorTime){ mirrorTime = timeStart; } - double size = satellite.second.toSize(mirrorTime, d2_in); + double size = satellite.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]); + if(satellite.isTime){ + amount = satellite.toTime(amount,pwd2[index]); } - satellite.second.setAmount(amount); + satellite.amount = amount; } } else { - satellite.second.setPosition(s,pwd2[satellite.first]); + satellite.setPosition(s,pwd2[index]); } _pparam->_vector.at(index) = satellite; SPLPEItem * splpeitem = dynamic_cast<SPLPEItem *>(item); @@ -347,26 +348,27 @@ FilletChamferKnotHolderEntity::knot_get() const if (!valid_index(index)) { return Point(infinity(), infinity()); } - std::pair<int,Geom::Satellite> satellite = _pparam->_vector.at(index); + Geom::Satellite satellite = _pparam->_vector.at(index); if(!_pparam->last_pointwise){ return Point(infinity(), infinity()); } - if(!satellite.second.getActive() || satellite.second.getHidden()){ + if(!satellite.active || satellite.hidden){ return Point(infinity(), infinity()); } Geom::Pointwise* pointwise = _pparam->last_pointwise; Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = pointwise->getPwd2(); - if(pwd2.size() <= (unsigned)satellite.first){ + Pathinfo pathInfo(pwd2); + if(pwd2.size() <= index){ return Point(infinity(), infinity()); } this->knot->show(); if( _index >= _pparam->_vector.size()){ - tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); - boost::optional<size_t> d2_prev_index = pointwise->getPrevious(satellite.first); + tmpPoint = satellite.getPosition(pwd2[index]); + boost::optional<size_t> d2_prev_index = pathInfo.getPrevious(index); 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 s = satellite.getSize(pwd2[index]); + double t = satellite.getOpositeTime(s,d2_in); if(t > 1){ t = 1; } @@ -374,17 +376,14 @@ FilletChamferKnotHolderEntity::knot_get() const t = 0; } double timeStart = 0; - std::vector<size_t> satIndexes = pointwise->findPeviousSatellites(satellite.first,1); - if(satIndexes.size()>0){ - timeStart = pointwise->getSatellites()[satIndexes[0]].second.getTime(d2_in); - } + timeStart = pointwise->getSatellites()[*d2_prev_index].getTime(d2_in); if(timeStart > t){ t = timeStart; } tmpPoint = (d2_in).valueAt(t); } } else { - tmpPoint = satellite.second.getPosition(pwd2[satellite.first]); + tmpPoint = satellite.getPosition(pwd2[index]); } Geom::Point const canvas_point = tmpPoint; return canvas_point; @@ -402,12 +401,12 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) } if (state & GDK_CONTROL_MASK) { if (state & GDK_MOD1_MASK) { - _pparam->_vector.at(index).second.setAmount(0.0); + _pparam->_vector.at(index).amount = 0.0; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); }else{ using namespace Geom; - SatelliteType type = _pparam->_vector.at(index).second.getSatelliteType(); + SatelliteType type = _pparam->_vector.at(index).satelliteType; switch(type){ case F: type = IF; @@ -422,7 +421,7 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) type = F; break; } - _pparam->_vector.at(index).second.setSatelliteType(type); + _pparam->_vector.at(index).satelliteType = type; _pparam->param_set_and_write_new_value(_pparam->_vector); sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); const gchar *tip; @@ -447,19 +446,28 @@ void FilletChamferKnotHolderEntity::knot_click(guint state) this->knot->show(); } } else if (state & GDK_SHIFT_MASK) { - double amount = _pparam->_vector.at(index).second.getAmount(); - if(!_pparam->use_distance && !_pparam->_vector.at(index).second.getIsTime()){ - amount = _pparam->last_pointwise->len_to_rad(amount, _pparam->_vector.at(index)); + Piecewise<D2<SBasis> > pwd2 = _pparam->last_pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); + double amount = _pparam->_vector.at(index).amount; + if(!_pparam->use_distance && !_pparam->_vector.at(index).isTime){ + boost::optional<size_t> prev = pathInfo.getPrevious(index); + boost::optional<Geom::D2<Geom::SBasis> > prevPwd2 = boost::none; + boost::optional<Geom::Satellite > prevSat = boost::none; + if(prev){ + prevPwd2 = pwd2[*prev]; + prevSat = _pparam->_vector.at(*prev); + } + amount = _pparam->_vector.at(index).len_to_rad(amount, prevPwd2, pwd2[index], prevSat); } bool aprox = false; D2<SBasis> d2_out = _pparam->last_pointwise->getPwd2()[index]; - boost::optional<size_t> d2_prev_index = _pparam->last_pointwise->getPrevious(_pparam->_vector.at(index).first); + boost::optional<size_t> d2_prev_index = pathInfo.getPrevious(index); 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); + this->desktop, amount , this, _pparam->unit, _pparam->use_distance, aprox, _pparam->documentUnit,_pparam->_vector.at(index)); } } @@ -473,16 +481,25 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Geom::Satellite satellite) if( _index >= _pparam->_vector.size()){ index = _index-_pparam->_vector.size(); } - double amount = satellite.getAmount(); + double amount = satellite.amount; double maxAmount = amount; - if(!_pparam->use_distance && !satellite.getIsTime()){ - amount = _pparam->last_pointwise->rad_to_len(amount, _pparam->_vector.at(index)); + if(!_pparam->use_distance && !satellite.isTime){ + Piecewise<D2<SBasis> > pwd2 = _pparam->last_pointwise->getPwd2(); + Pathinfo pathInfo(pwd2); + boost::optional<size_t> prev = pathInfo.getPrevious(index); + boost::optional<Geom::D2<Geom::SBasis> > prevPwd2 = boost::none; + boost::optional<Geom::Satellite > prevSat = boost::none; + if(prev){ + prevPwd2 = pwd2[*prev]; + prevSat = _pparam->_vector.at(*prev); + } + amount = _pparam->_vector.at(index).rad_to_len(amount, prevPwd2, pwd2[index], prevSat); if(maxAmount > 0 && amount == 0){ - amount = _pparam->_vector.at(index).second.getAmount(); + amount = _pparam->_vector.at(index).amount; } } - satellite.setAmount(amount); - _pparam->_vector.at(index).second = satellite; + satellite.amount = amount; + _pparam->_vector.at(index) = satellite; this->parent_holder->knot_ungrabbed_handler(this->knot, 0); _pparam->param_set_and_write_new_value(_pparam->_vector); SPLPEItem * splpeitem = dynamic_cast<SPLPEItem *>(item); diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitearray.h index fcd3bd736..ee0cfbad3 100644 --- a/src/live_effects/parameter/satellitepairarray.h +++ b/src/live_effects/parameter/satellitearray.h @@ -18,11 +18,11 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include <glib.h> #include "live_effects/parameter/array.h" #include "live_effects/effect-enum.h" +#include "helper/geom-pointwise.h" #include "knot-holder-entity.h" -#include <2geom/pointwise.h> +#include <glib.h> namespace Inkscape { @@ -30,14 +30,14 @@ namespace LivePathEffect { class FilletChamferKnotHolderEntity; -class SatellitePairArrayParam : public ArrayParam<std::pair<size_t, Geom::Satellite> > { +class SatelliteArrayParam : public ArrayParam<Geom::Satellite> { public: - SatellitePairArrayParam(const Glib::ustring &label, + SatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect); - virtual ~SatellitePairArrayParam(); + virtual ~SatelliteArrayParam(); virtual Gtk::Widget * param_newWidget() { return NULL; @@ -66,8 +66,8 @@ public: protected: KnotHolder *knoth; private: - SatellitePairArrayParam(const SatellitePairArrayParam &); - SatellitePairArrayParam &operator=(const SatellitePairArrayParam &); + SatelliteArrayParam(const SatelliteArrayParam &); + SatelliteArrayParam &operator=(const SatelliteArrayParam &); SPKnotShapeType knot_shape; SPKnotModeType knot_mode; @@ -84,7 +84,7 @@ private: class FilletChamferKnotHolderEntity : public KnotHolderEntity { public: - FilletChamferKnotHolderEntity(SatellitePairArrayParam *p, size_t index); + FilletChamferKnotHolderEntity(SatelliteArrayParam *p, size_t index); virtual ~FilletChamferKnotHolderEntity() {_pparam->knoth = NULL;} virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state); @@ -97,7 +97,7 @@ public: }; private: - SatellitePairArrayParam *_pparam; + SatelliteArrayParam *_pparam; size_t _index; }; |
