summaryrefslogtreecommitdiffstats
path: root/src/live_effects/parameter/satellitesarray.cpp
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2016-05-10 21:16:49 +0000
committerjabiertxof <info@marker.es>2016-05-10 21:16:49 +0000
commit07717a370b8efe6ddbb0c69d115bb063a2e7686a (patch)
treedf507f7bc83681ce315137c5828ce6c8b24cdf76 /src/live_effects/parameter/satellitesarray.cpp
parentupdate to trunk (diff)
downloadinkscape-07717a370b8efe6ddbb0c69d115bb063a2e7686a.tar.gz
inkscape-07717a370b8efe6ddbb0c69d115bb063a2e7686a.zip
Working with path updates
(bzr r13645.1.130)
Diffstat (limited to 'src/live_effects/parameter/satellitesarray.cpp')
-rw-r--r--src/live_effects/parameter/satellitesarray.cpp310
1 files changed, 156 insertions, 154 deletions
diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp
index 9274a4aff..9f14a1d5b 100644
--- a/src/live_effects/parameter/satellitesarray.cpp
+++ b/src/live_effects/parameter/satellitesarray.cpp
@@ -26,7 +26,7 @@ SatellitesArrayParam::SatellitesArrayParam(const Glib::ustring &label,
const Glib::ustring &key,
Inkscape::UI::Widget::Registry *wr,
Effect *effect)
- : ArrayArrayParam<ArrayArrayParam<Satellite> >(label, tip, key, wr, effect, 0), knoth(NULL)
+ : ArrayParam<std::vector<Satellite> >(label, tip, key, wr, effect, 0), knoth(NULL)
{
_knot_shape = SP_KNOT_SHAPE_DIAMOND;
_knot_mode = SP_KNOT_MODE_XOR;
@@ -77,104 +77,106 @@ void SatellitesArrayParam::updateCanvasIndicators(bool mirror)
if (mirror == true) {
_hp.clear();
}
- for (size_t i = 0; i < _vector.size(); ++i) {
- for (size_t j = 0; j < _vector[i].size(); ++j) {
- if (!_vector[i][j].active || _vector[i][j].hidden) {
- continue;
- }
- if ((!_vector[i][j].has_mirror && mirror == true) || _vector[i][j].amount == 0) {
- continue;
- }
- double pos = 0;
- if (pathv.size() <= i || pathv[i].size() <= j) {
- break;
- }
- Geom::Curve *curve_in = pathv[i][j].duplicate();
- bool overflow = false;
- double size_out = _vector[i][j].arcDistance(*curve_in);
- double lenght_out = curve_in->length();
- double lenght_in = 0;
-
- boost::optional<size_t> curve_prev_index = boost::none;
- if(j == 0 && pathv[i].closed()){
- curve_prev_index = pathv[pathv[i].size() - 1];
- } else if(!pathv[i].closed() || j != 0) {
- curve_prev_index = j - 1;
- }
- if (curve_prev_index) {
- lenght_in = pathv.curveAt(*curve_prev_index).length();
- }
- if (mirror == true) {
+ if (_effectType == FILLET_CHAMFER) {
+ for (size_t i = 0; i < _vector.size(); ++i) {
+ for (size_t j = 0; j < _vector[i].size(); ++j) {
+ if ( _vector[i][j].hidden) {
+ continue;
+ }
+ if ((!_vector[i][j].has_mirror && mirror == true) || _vector[i][j].amount == 0) {
+ continue;
+ }
+ double pos = 0;
+ if (pathv[i].size() == j) { //ignore last satellite in open paths with fillet chamfer effect
+ continue;
+ }
+ Geom::Curve *curve_in = pathv[i][j].duplicate();
+ bool overflow = false;
+ double size_out = _vector[i][j].arcDistance(*curve_in);
+ double lenght_out = curve_in->length();
+ double lenght_in = 0;
+
+ boost::optional<size_t> curve_prev_index = boost::none;
+ if(j == 0 && pathv[i].closed()){
+ curve_prev_index = pathv[i].size() - 1;
+ } else if(!pathv[i].closed() || j != 0) {
+ curve_prev_index = j - 1;
+ }
if (curve_prev_index) {
- curve_in = const_cast<Geom::Curve *>(&pathv.curveAt(*curve_prev_index));
- pos = _vector[i][j].time(size_out, true, *curve_in);
- if (lenght_out < size_out) {
+ lenght_in = pathv.curveAt(*curve_prev_index).length();
+ }
+ if (mirror) {
+ if (curve_prev_index) {
+ curve_in = const_cast<Geom::Curve *>(&pathv.curveAt(*curve_prev_index));
+ pos = _vector[i][j].time(size_out, true, *curve_in);
+ if (lenght_out < size_out) {
+ overflow = true;
+ }
+ }
+ } else {
+ pos = _vector[i][j].time(*curve_in);
+ if (lenght_in < size_out) {
overflow = true;
}
}
- } else {
- pos = _vector[i][j].time(*curve_in);
- if (lenght_in < size_out) {
- overflow = true;
+ if (pos <= 0 || pos >= 1) {
+ continue;
}
- }
- if (pos <= 0 || pos >= 1) {
- continue;
- }
- Geom::Point point_a = curve_in->pointAt(pos);
- Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos));
- Geom::Rotate rot(Geom::Rotate::from_degrees(-90));
- deriv_a = deriv_a * rot;
- Geom::Point point_c = point_a - deriv_a * _helper_size;
- Geom::Point point_d = point_a + deriv_a * _helper_size;
- Geom::Ray ray_1(point_c, point_d);
- char const *svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5";
- Geom::PathVector pathv = sp_svg_read_pathv(svgd);
- Geom::Affine aff = Geom::Affine();
- aff *= Geom::Scale(_helper_size);
- if (mirror == true) {
- aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90));
- } else {
- aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270));
- }
- aff *= Geom::Translate(curve_in->pointAt(pos));
- pathv *= aff;
- _hp.push_back(pathv[0]);
- _hp.push_back(pathv[1]);
- if (overflow) {
- double diameter = _helper_size;
- if (_helper_size == 0) {
- diameter = 15;
- char const *svgd;
- svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 "
- "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z";
- Geom::PathVector pathv = sp_svg_read_pathv(svgd);
- aff = Geom::Affine();
- aff *= Geom::Scale(diameter);
- aff *= Geom::Translate(point_a - Geom::Point(diameter * 0.35, diameter * 0.35));
- pathv *= aff;
- _hp.push_back(pathv[0]);
+ Geom::Point point_a = curve_in->pointAt(pos);
+ Geom::Point deriv_a = unit_vector(derivative(curve_in->toSBasis()).pointAt(pos));
+ Geom::Rotate rot(Geom::Rotate::from_degrees(-90));
+ deriv_a = deriv_a * rot;
+ Geom::Point point_c = point_a - deriv_a * _helper_size;
+ Geom::Point point_d = point_a + deriv_a * _helper_size;
+ Geom::Ray ray_1(point_c, point_d);
+ char const *svgd = "M 1,0.25 0.5,0 1,-0.25 M 1,0.5 0,0 1,-0.5";
+ Geom::PathVector pathv = sp_svg_read_pathv(svgd);
+ Geom::Affine aff = Geom::Affine();
+ aff *= Geom::Scale(_helper_size);
+ if (mirror) {
+ aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90));
} else {
- char const *svgd;
- svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A "
- "1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 "
- "0 -1.32 z";
- Geom::PathVector pathv = sp_svg_read_pathv(svgd);
- aff = Geom::Affine();
- aff *= Geom::Scale(_helper_size / 2.0);
- if (mirror == true) {
- aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90));
+ aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270));
+ }
+ aff *= Geom::Translate(curve_in->pointAt(pos));
+ pathv *= aff;
+ _hp.push_back(pathv[0]);
+ _hp.push_back(pathv[1]);
+ if (overflow) {
+ double diameter = _helper_size;
+ if (_helper_size == 0) {
+ diameter = 15;
+ char const *svgd;
+ svgd = "M 0.7,0.35 A 0.35,0.35 0 0 1 0.35,0.7 0.35,0.35 0 0 1 0,0.35 "
+ "0.35,0.35 0 0 1 0.35,0 0.35,0.35 0 0 1 0.7,0.35 Z";
+ Geom::PathVector pathv = sp_svg_read_pathv(svgd);
+ aff = Geom::Affine();
+ aff *= Geom::Scale(diameter);
+ aff *= Geom::Translate(point_a - Geom::Point(diameter * 0.35, diameter * 0.35));
+ pathv *= aff;
+ _hp.push_back(pathv[0]);
} else {
- aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270));
+ char const *svgd;
+ svgd = "M 0 -1.32 A 1.32 1.32 0 0 0 -1.32 0 A 1.32 1.32 0 0 0 0 1.32 A "
+ "1.32 1.32 0 0 0 1.18 0.59 L 0 0 L 1.18 -0.59 A 1.32 1.32 0 0 0 "
+ "0 -1.32 z";
+ Geom::PathVector pathv = sp_svg_read_pathv(svgd);
+ aff = Geom::Affine();
+ aff *= Geom::Scale(_helper_size / 2.0);
+ if (mirror) {
+ aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(90));
+ } else {
+ aff *= Geom::Rotate(ray_1.angle() - Geom::rad_from_deg(270));
+ }
+ aff *= Geom::Translate(curve_in->pointAt(pos));
+ pathv *= aff;
+ _hp.push_back(pathv[0]);
}
- aff *= Geom::Translate(curve_in->pointAt(pos));
- pathv *= aff;
- _hp.push_back(pathv[0]);
}
}
}
}
- if (mirror == true) {
+ if (mirror) {
updateCanvasIndicators(false);
}
}
@@ -198,8 +200,7 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul,
for (size_t i = 0; i < _vector.size(); ++i) {
for (size_t j = 0; j < _vector[i].size(); ++j) {
if (!_vector[i][j].is_time && _vector[i][j].amount > 0) {
- _vector[i][j].amount = _vector[i][j].amount *
- ((postmul.expansionX() + postmul.expansionY()) / 2);
+ _vector[i][j].amount = _vector[i][j].amount * ((postmul.expansionX() + postmul.expansionY()) / 2);
}
}
}
@@ -208,24 +209,22 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul,
}
void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder,
- SPDesktop *desktop,
- SPItem *item, bool mirror)
+ SPDesktop *desktop,
+ SPItem *item, bool mirror)
{
for (size_t i = 0; i < _vector.size(); ++i) {
for (size_t j = 0; j < _vector[i].size(); ++j) {
- size_t iPlus = j;
- if (mirror == true) {
- iPlus = j + _vector[i].size();
- }
- if (!_vector[i][j].active) {
+ if (!_vector[i][j].has_mirror && mirror) {
continue;
}
- if (!_vector[i][j].has_mirror && mirror == true) {
- continue;
+ SatelliteType type = _vector[i][j].satellite_type;
+ size_t index = i;
+ size_t subindex = j;
+ if (mirror) {
+ subindex = subindex + _vector[i].size();
}
using namespace Geom;
- SatelliteType type = _vector[i][j].satellite_type;
- //IF is for filletChamfer effect...
+ //If is for filletChamfer effect...
if (_effectType == FILLET_CHAMFER) {
const gchar *tip;
if (type == CHAMFER) {
@@ -245,15 +244,13 @@ void SatellitesArrayParam::addKnotHolderEntities(KnotHolder *knotholder,
"<b>Shift+Click</b> open dialog, "
"<b>Ctrl+Alt+Click</b> reset");
}
- FilletChamferKnotHolderEntity *e =
- new FilletChamferKnotHolderEntity(this, i, iPlus);
- e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip),
- _knot_shape, _knot_mode, _knot_color);
+ FilletChamferKnotHolderEntity *e = new FilletChamferKnotHolderEntity(this, index, subindex);
+ e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip),_knot_shape, _knot_mode, _knot_color);
knotholder->add(e);
}
}
}
- if (mirror == true) {
+ if (mirror) {
addKnotHolderEntities(knotholder, desktop, item, false);
}
}
@@ -279,7 +276,7 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p,
if (_subindex >= _pparam->_vector[_index].size()) {
subindex = _subindex - _pparam->_vector[_index].size();
}
- if (!valid_index(subindex)) {
+ if (!valid_index(_index)) {
return;
}
@@ -287,39 +284,39 @@ void FilletChamferKnotHolderEntity::knot_set(Geom::Point const &p,
return;
}
- Satellite satellite = _pparam->_vector[_index].at(subindex);
- if (!satellite.active || satellite.hidden) {
+ Satellite satellite = _pparam->_vector[_index][subindex];
+ if (satellite.hidden) {
return;
}
Pointwise *pointwise = _pparam->_last_pointwise;
- Geom::PathVector pathv = pparam->_last_pointwise->getPV();
- if (_subindex >= _pparam->_vector[_index].size() ) {
+ Geom::PathVector pathv = pointwise->getPV();
+ if (subindex != _subindex) {
boost::optional<size_t> curve_prev_index = boost::none;
- if(_subindex == 0 && pathv[_index].closed()){
- curve_prev_index = pathv[pathv[_index].size() - 1];
- } else if(!pathv[_index].closed() || _subindex != 0) {
- curve_prev_index = _subindex - 1;
+ if(subindex == 0 && pathv[_index].closed()){
+ curve_prev_index = pathv[_index].size() - 1;
+ } else if(!pathv[_index].closed() || subindex != 0) {
+ curve_prev_index = subindex - 1;
}
if (curve_prev_index) {
Geom::Curve const &curve_in = pathv[_index][*curve_prev_index];
double mirror_time = Geom::nearest_time(s, curve_in);
double time_start = 0;
- Satellites sats = pointwise->getSatellites();
- time_start = sats[_index][*curve_prev_index].time(curve_in);
+ Satellites satellites = pointwise->getSatellites();
+ time_start = satellites[_index][*curve_prev_index].time(curve_in);
if (time_start > mirror_time) {
mirror_time = time_start;
}
double size = arcLengthAt(mirror_time, curve_in);
double amount = curve_in.length() - size;
if (satellite.is_time) {
- amount = timeAtArcLength(amount, pathv[_index][);
+ amount = timeAtArcLength(amount, pathv[_index][subindex]);
}
satellite.amount = amount;
}
} else {
- satellite.setPosition(s, pathv[_index]);
+ satellite.setPosition(s, pathv[_index][subindex]);
}
- _pparam->_vector[_index][_subindex] = satellite;
+ _pparam->_vector[_index][subindex] = satellite;
SPLPEItem *splpeitem = dynamic_cast<SPLPEItem *>(item);
if (splpeitem) {
sp_lpe_item_update_patheffect(splpeitem, false, false);
@@ -333,33 +330,41 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const
if (_subindex >= _pparam->_vector[_index].size()) {
subindex = _subindex - _pparam->_vector[_index].size();
}
- if (!valid_index(_subindex)) {
+ if (!valid_index(_index)) {
return Geom::Point(Geom::infinity(), Geom::infinity());
}
- Satellite satellite = _pparam->_vector[_index][_subindex];
- if (!_pparam->_last_pointwise) {
+ Satellite satellite = _pparam->_vector[_index][subindex];
+ Pointwise *pointwise = _pparam->_last_pointwise;
+ if (!pointwise) {
return Geom::Point(Geom::infinity(), Geom::infinity());
}
- if (!satellite.active || satellite.hidden) {
+ Geom::PathVector pathv = pointwise->getPV();
+ if (pathv[_index].size() <= subindex){ //We know this path is open and is last satellite. Hide it
+ _pparam->_vector[_index][subindex].hidden = true;
return Geom::Point(Geom::infinity(), Geom::infinity());
}
- Pointwise *pointwise = _pparam->_last_pointwise;
- Geom::PathVector pathv = pparam->_last_pointwise->getPV();
- if (pathv[_index].size() <= subindex) {
+ if (!pathv[_index].closed() && subindex == 0){ //Path is open hide first satellite
+ _pparam->_vector[_index][subindex].hidden = true;
+ return Geom::Point(Geom::infinity(), Geom::infinity());
+ }
+ if (satellite.hidden) {
+ return Geom::Point(Geom::infinity(), Geom::infinity());
+ }
+ if (subindex != _subindex && !_pparam->_vector[_index][subindex].has_mirror) {
return Geom::Point(Geom::infinity(), Geom::infinity());
}
this->knot->show();
- if (_subindex >= _pparam->_vector[index].size()) {
- tmp_point = satellite.getPosition(pathv[_index][_subindex]);
+ if (subindex != _subindex) {
+ tmp_point = satellite.getPosition(pathv[_index][subindex]);
boost::optional<size_t> curve_prev_index = boost::none;
- if(_subindex == 0 && pathv[_index].closed()){
- curve_prev_index = pathv[pathv[_index].size() - 1];
- } else if(!pathv[_index].closed() || _subindex != 0) {
- curve_prev_index = _subindex - 1;
+ if(subindex == 0 && pathv[_index].closed()){
+ curve_prev_index = pathv[_index].size() - 1;
+ } else if(!pathv[_index].closed() || subindex != 0) {
+ curve_prev_index = subindex - 1;
}
if (curve_prev_index) {
Geom::Curve const &curve_in = pathv[_index][*curve_prev_index];
- double s = satellite.arcDistance(pathv[_index][_subindex]);
+ double s = satellite.arcDistance(pathv[_index][subindex]);
double t = satellite.time(s, true, curve_in);
if (t > 1) {
t = 1;
@@ -375,7 +380,7 @@ Geom::Point FilletChamferKnotHolderEntity::knot_get() const
tmp_point = (curve_in).pointAt(t);
}
} else {
- tmp_point = satellite.getPosition(pathv[_index][_subindex]);
+ tmp_point = satellite.getPosition(pathv[_index][subindex]);
}
Geom::Point const canvas_point = tmp_point;
return canvas_point;
@@ -386,19 +391,18 @@ void FilletChamferKnotHolderEntity::knot_click(guint state)
if (!_pparam->_last_pointwise) {
return;
}
-
size_t subindex = _subindex;
if (_subindex >= _pparam->_vector[_index].size()) {
subindex = _subindex - _pparam->_vector[_index].size();
}
if (state & GDK_CONTROL_MASK) {
if (state & GDK_MOD1_MASK) {
- _pparam->_vector[_index][_subindex].amount = 0.0;
+ _pparam->_vector[_index][subindex].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[_index][_subindex].satellite_type;
+ SatelliteType type = _pparam->_vector[_index][subindex].satellite_type;
switch (type) {
case FILLET:
type = INVERSE_FILLET;
@@ -438,13 +442,13 @@ void FilletChamferKnotHolderEntity::knot_click(guint state)
this->knot->show();
}
} else if (state & GDK_SHIFT_MASK) {
- Geom::PathVector pathv = pparam->_last_pointwise->getPV();
- double amount = _pparam->_vector[_index][_subindex].amount;
+ Geom::PathVector pathv = _pparam->_last_pointwise->getPV();
+ double amount = _pparam->_vector[_index][subindex].amount;
boost::optional<size_t> curve_prev_index = boost::none;
- if(_subindex == 0 && pathv[_index].closed()){
- curve_prev_index = pathv[pathv[_index].size() - 1];
- } else if(!pathv[_index].closed() || _subindex != 0) {
- curve_prev_index = _subindex - 1;
+ if(subindex == 0 && pathv[_index].closed()){
+ curve_prev_index = pathv[_index].size() - 1;
+ } else if(!pathv[_index].closed() || subindex != 0) {
+ curve_prev_index = subindex - 1;
}
if (!_pparam->_use_distance && !_pparam->_vector[_index][subindex].is_time) {
if (curve_prev_index) {
@@ -454,10 +458,9 @@ void FilletChamferKnotHolderEntity::knot_click(guint state)
}
}
bool aprox = false;
- Geom::D2<Geom::SBasis> d2_out = _pparam->_last_pointwise->getPwd2()[_index][subindex];
+ Geom::D2<Geom::SBasis> d2_out = pathv[_index][subindex].toSBasis();
if (curve_prev_index) {
- Geom::D2<Geom::SBasis> d2_in =
- _pparam->_last_pointwise->getPwd2()[_index][*curve_prev_index];
+ Geom::D2<Geom::SBasis> d2_in = pathv[_index][*curve_prev_index].toSBasis();
aprox = ((d2_in)[0].degreesOfFreedom() != 2 ||
d2_out[0].degreesOfFreedom() != 2) &&
!_pparam->_use_distance
@@ -483,17 +486,16 @@ void FilletChamferKnotHolderEntity::knot_set_offset(Satellite satellite)
double amount = satellite.amount;
double max_amount = amount;
if (!_pparam->_use_distance && !satellite.is_time) {
- Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = _pparam->_last_pointwise->getPwd2();
- Geom::PathVector pathv = path_from_piecewise(Geom::remove_short_cuts(pwd2,0.01),0.01);
- Geom::Path sat_path = pathv.pathAt(index);
+ Pointwise *pointwise = _pparam->_last_pointwise;
+ Geom::PathVector pathv = pointwise->getPV();
boost::optional<size_t> curve_prev_index = boost::none;
- if(_subindex == 0 && pathv[_index].closed()){
- curve_prev_index = pathv[pathv[_index].size() - 1];
- } else if(!pathv[_index].closed() || _subindex != 0) {
- curve_prev_index = _subindex - 1;
+ if(subindex == 0 && pathv[_index].closed()){
+ curve_prev_index = pathv[_index].size() - 1;
+ } else if(!pathv[_index].closed() || subindex != 0) {
+ curve_prev_index = subindex - 1;
}
if (curve_prev_index) {
- amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][*prev], pathv[_index][subindex]);
+ amount = _pparam->_vector[_index][subindex].radToLen(amount, pathv[_index][*curve_prev_index], pathv[_index][subindex]);
} else {
amount = 0.0;
}