summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-04-03 14:10:46 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-04-03 14:10:46 +0000
commit04218b26ae0a10bf9e64721fb0dd789f024afca5 (patch)
treec04908e81a3f2fc4e1c34418a9b2d10e98e8cdc3 /src
parentupdate to trunk (diff)
downloadinkscape-04218b26ae0a10bf9e64721fb0dd789f024afca5.tar.gz
inkscape-04218b26ae0a10bf9e64721fb0dd789f024afca5.zip
Update pathinfo class to allow piecewise and pathvector as input.
Add a method on pointwise to allow update if degenerated curves in new path, not noticed by piecewises (bzr r13645.1.72)
Diffstat (limited to 'src')
-rw-r--r--src/helper/geom-pathinfo.cpp42
-rw-r--r--src/helper/geom-pathinfo.h12
-rw-r--r--src/helper/geom-pointwise.cpp62
-rw-r--r--src/helper/geom-pointwise.h3
-rw-r--r--src/live_effects/lpe-fillet-chamfer.cpp38
-rw-r--r--src/live_effects/lpe-fillet-chamfer.h2
-rw-r--r--src/ui/tool/multi-path-manipulator.cpp10
-rw-r--r--src/ui/tool/path-manipulator.cpp7
8 files changed, 107 insertions, 69 deletions
diff --git a/src/helper/geom-pathinfo.cpp b/src/helper/geom-pathinfo.cpp
index f12004535..f9d4e5dbb 100644
--- a/src/helper/geom-pathinfo.cpp
+++ b/src/helper/geom-pathinfo.cpp
@@ -19,25 +19,40 @@ namespace Geom {
*/
Pathinfo::Pathinfo(Piecewise<D2<SBasis> > pwd2) : _pwd2(pwd2)
{
- _setPathInfo();
+ _setPathInfo(pwd2);
+}
+;
+Pathinfo::Pathinfo(Geom::PathVector path_vector) : _path_vector(path_vector)
+{
+ _setPathInfo(path_vector);
}
;
Pathinfo::~Pathinfo() {}
;
-void Pathinfo::setPwd2(Piecewise<D2<SBasis> > pwd2_in)
+void Pathinfo::setPwd2(Piecewise<D2<SBasis> > pwd2)
+{
+ _pwd2 = pwd2;
+ _setPathInfo(pwd2);
+}
+
+void Pathinfo::setPathVector(Geom::PathVector path_vector)
{
- _pwd2 = pwd2_in;
- _setPathInfo();
+ _path_vector = path_vector;
+ _setPathInfo(path_vector);
}
+void Pathinfo::_setPathInfo(Piecewise<D2<SBasis> > pwd2)
+{
+ _setPathInfo(path_from_piecewise(remove_short_cuts(pwd2, 0.1), 0.001));
+}
/** Store the base path data
*/
-void Pathinfo::_setPathInfo()
+void Pathinfo::_setPathInfo(Geom::PathVector path_vector)
{
data.clear();
- std::vector<Geom::Path> path_in =
+ Geom::PathVector path_in =
path_from_piecewise(remove_short_cuts(_pwd2, 0.1), 0.001);
size_t counter = 0;
for (PathVector::const_iterator path_it = path_in.begin();
@@ -65,6 +80,11 @@ void Pathinfo::_setPathInfo()
}
}
+size_t Pathinfo::numberCurves() const
+{
+ return data.back().first;
+}
+
size_t Pathinfo::subPathIndex(size_t index) const
{
for (size_t i = 0; i < data.size(); i++) {
@@ -101,10 +121,10 @@ size_t Pathinfo::first(size_t index) const
boost::optional<size_t> Pathinfo::previous(size_t index) const
{
- if (first(index) == index && isClosed(index)) {
+ if (first(index) == index && closed(index)) {
return last(index);
}
- if (first(index) == index && !isClosed(index)) {
+ if (first(index) == index && !closed(index)) {
return boost::none;
}
return index - 1;
@@ -112,16 +132,16 @@ boost::optional<size_t> Pathinfo::previous(size_t index) const
boost::optional<size_t> Pathinfo::next(size_t index) const
{
- if (last(index) == index && isClosed(index)) {
+ if (last(index) == index && closed(index)) {
return first(index);
}
- if (last(index) == index && !isClosed(index)) {
+ if (last(index) == index && !closed(index)) {
return boost::none;
}
return index + 1;
}
-bool Pathinfo::isClosed(size_t index) const
+bool Pathinfo::closed(size_t index) const
{
for (size_t i = 0; i < data.size(); i++) {
if (index <= data[i].first) {
diff --git a/src/helper/geom-pathinfo.h b/src/helper/geom-pathinfo.h
index c9d8e2862..c41d92e7a 100644
--- a/src/helper/geom-pathinfo.h
+++ b/src/helper/geom-pathinfo.h
@@ -23,20 +23,24 @@ namespace Geom {
class Pathinfo {
public:
Pathinfo(Piecewise<D2<SBasis> > pwd2);
+ Pathinfo(Geom::PathVector path_vector);
virtual ~Pathinfo();
- void setPwd2(Piecewise<D2<SBasis> > pwd2_in);
+ void setPwd2(Piecewise<D2<SBasis> > pwd2);
+ void setPathVector(Geom::PathVector path_vector);
+ size_t numberCurves() const;
size_t subPathIndex(size_t index) const;
size_t last(size_t index) const;
size_t first(size_t index) const;
boost::optional<size_t> previous(size_t index) const;
boost::optional<size_t> next(size_t index) const;
- bool isClosed(size_t index) const;
- std::vector<std::pair<size_t, bool> > pathInfo() const;
+ bool closed(size_t index) const;
std::vector<std::pair<size_t, bool> > data;
private:
- void _setPathInfo();
+ void _setPathInfo(Geom::PathVector path_vector);
+ void _setPathInfo(Piecewise<D2<SBasis> > pwd2);
Piecewise<D2<SBasis> > _pwd2;
+ Geom::PathVector _path_vector;
};
} //namespace Geom
diff --git a/src/helper/geom-pointwise.cpp b/src/helper/geom-pointwise.cpp
index 261d2bff4..714573ad5 100644
--- a/src/helper/geom-pointwise.cpp
+++ b/src/helper/geom-pointwise.cpp
@@ -66,7 +66,7 @@ void Pointwise::setStart()
for (size_t i = 0; i < path_info.size(); i++) {
size_t firstNode = _path_info.first(path_info[i].first);
size_t lastNode = _path_info.last(path_info[i].first);
- if (!_path_info.isClosed(lastNode)) {
+ if (!_path_info.closed(lastNode)) {
_satellites[firstNode].hidden = true;
_satellites[firstNode].active = false;
} else {
@@ -78,12 +78,14 @@ void Pointwise::setStart()
/** Fired when a path is modified.
*/
-void Pointwise::recalculateForNewPwd2(Piecewise<D2<SBasis> > A)
+void Pointwise::recalculateForNewPwd2(Piecewise<D2<SBasis> > A, Geom::PathVector B)
{
if (_pwd2.size() > A.size()) {
pwd2Sustract(A);
} else if (_pwd2.size() < A.size()) {
pwd2Append(A);
+ } else {
+ insertDegenerateSatellites(A,B);
}
}
@@ -123,7 +125,6 @@ void Pointwise::pwd2Append(Piecewise<D2<SBasis> > A)
size_t new_subpath_index = _path_info.subPathIndex(i);
_path_info.setPwd2(_pwd2);
bool subpath_is_changed = false;
- bool not_exist = ;
if (_pwd2.size() <= i - counter) {
subpath_is_changed = false;
} else {
@@ -140,9 +141,8 @@ void Pointwise::pwd2Append(Piecewise<D2<SBasis> > A)
subpathReverse(first, last);
reversed = true;
}
- if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001) ||
- /*this condition for duplicate node Shift+d*/(i > 0 && are_near(A[i - 1].at0(), A[i].at0(), 0.001) &&
- !are_near(_pwd2[i - counter].at0(), _pwd2[i - counter - 1].at0(), 0.001))){
+
+ if (_pwd2.size() <= i - counter || !are_near(_pwd2[i - counter].at0(), A[i].at0(), 0.001)){
counter++;
bool active = true;
bool hidden = false;
@@ -231,6 +231,56 @@ void Pointwise::subpathReverse(size_t start, size_t end)
setPwd2(remove_short_cuts(paths_to_pw(tmp_path), 0.01));
}
+
+/** Fired when a path is modified duplicating a node. Piecewise ignore degenerated curves.
+ */
+void Pointwise::insertDegenerateSatellites(Piecewise<D2<SBasis> > A, Geom::PathVector B)
+{
+ size_t size_A = A.size();
+ _path_info.setPathVector(B);
+ size_t size_B = _path_info.numberCurves();
+ size_t satellite_gap = size_B - size_A;
+ if (satellite_gap == 0){
+ return;
+ }
+ size_t counter = 0;
+ size_t counter_added = 0;
+ for (PathVector::const_iterator path_it = B.begin();
+ path_it != B.end(); ++path_it) {
+ if (path_it->empty()) {
+ continue;
+ }
+ Geom::Path::const_iterator curve_it1 = path_it->begin();
+ Geom::Path::const_iterator curve_endit = path_it->end_default();
+ if (path_it->closed()) {
+ const Curve &closingline = path_it->back_closed();
+ if (are_near(closingline.initialPoint(), closingline.finalPoint())) {
+ curve_endit = path_it->end_open();
+ }
+ }
+ while (curve_it1 != curve_endit) {
+ if ((*curve_it1).isDegenerate() && counter_added < satellite_gap){
+ counter_added++;
+ bool active = true;
+ bool hidden = false;
+ bool is_time = _satellites[0].isTime;
+ bool mirror_knots = _satellites[0].hasMirror;
+ double amount = 0.0;
+ double degrees = 0.0;
+ int steps = 0;
+ Satellite sat(_satellites[0].satelliteType, is_time, active, mirror_knots,
+ hidden, amount, degrees, steps);
+ _satellites.insert(_satellites.begin() + counter ,sat);
+ }
+ ++curve_it1;
+ counter++;
+ }
+ }
+
+ _path_info.setPwd2(A);
+ setPwd2(A);
+}
+
} // namespace Geom
/*
Local Variables:
diff --git a/src/helper/geom-pointwise.h b/src/helper/geom-pointwise.h
index 3ce1ca75a..48ee36255 100644
--- a/src/helper/geom-pointwise.h
+++ b/src/helper/geom-pointwise.h
@@ -48,11 +48,12 @@ public:
void setStart();
- void recalculateForNewPwd2(Piecewise<D2<SBasis> > A);
+ void recalculateForNewPwd2(Piecewise<D2<SBasis> > A, Geom::PathVector B);
void pwd2Sustract(Piecewise<D2<SBasis> > A);
void pwd2Append(Piecewise<D2<SBasis> > A);
void subpathToBack(size_t subpath);
void subpathReverse(size_t start, size_t end);
+ void insertDegenerateSatellites(Piecewise<D2<SBasis> > A, Geom::PathVector B);
private:
Piecewise<D2<SBasis> > _pwd2;
diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp
index f7fd6f64b..fdf2469e0 100644
--- a/src/live_effects/lpe-fillet-chamfer.cpp
+++ b/src/live_effects/lpe-fillet-chamfer.cpp
@@ -66,7 +66,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject)
"ignore_radius_0", &wr, this, false),
helper_size(_("Helper size with direction:"),
_("Helper size with direction"), "helper_size", &wr, this, 0),
- pointwise(NULL), segment_size(0)
+ pointwise(NULL)
{
registerParameter(&satellites_param);
registerParameter(&unit);
@@ -288,7 +288,7 @@ void LPEFilletChamfer::updateAmount()
Pathinfo path_info(pwd2);
for (std::vector<Geom::Satellite>::iterator it = satellites.begin();
it != satellites.end(); ++it) {
- if (!path_info.isClosed(it - satellites.begin()) &&
+ if (!path_info.closed(it - satellites.begin()) &&
path_info.first(it - satellites.begin()) ==
(unsigned)(it - satellites.begin())) {
it->amount = 0;
@@ -401,17 +401,11 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem)
doOnApply(lpeItem);
sats = satellites_param.data();
}
- //optional call
- if (satellites_param.knoth) {
- satellites_param.knoth->update_knots();
- }
if (hide_knots) {
satellites_param.setHelperSize(0);
} else {
satellites_param.setHelperSize(helper_size);
}
- bool refresh = false;
- bool hide = true;
for (std::vector<Satellite>::iterator it = sats.begin();
it != sats.end();) {
if (it->isTime != flexible) {
@@ -428,45 +422,23 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem)
}
if (it->hasMirror != mirror_knots) {
it->hasMirror = mirror_knots;
- refresh = true;
- }
- if (it->hidden == false) {
- hide = false;
}
it->hidden = hide_knots;
++it;
}
- if (hide != hide_knots) {
- refresh = true;
- }
-
- if (pointwise && c->get_segment_count() != segment_size && segment_size != 0) {
- pointwise->recalculateForNewPwd2(pwd2_in);
- segment_size = c->get_segment_count();
+ if (pointwise && c->get_segment_count() != sats.size()) {
+ pointwise->recalculateForNewPwd2(pwd2_in, original_pathv);
} else {
pointwise = new Pointwise(pwd2_in, sats);
- segment_size = c->get_segment_count();
}
satellites_param.setPointwise(pointwise);
- if (refresh) {
- refreshKnots();
- }
+ refreshKnots();
} else {
g_warning("LPE Fillet can only be applied to shapes (not groups).");
}
}
void
-LPEFilletChamfer::adjustForNewPath(std::vector<Geom::Path> const &path_in)
-{
- if (!path_in.empty() && pointwise) {
- pointwise->recalculateForNewPwd2(remove_short_cuts(
- paths_to_pw(pathv_to_linear_and_cubic_beziers(path_in)), 0.01));
- satellites_param.setPointwise(pointwise);
- }
-}
-
-void
LPEFilletChamfer::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
{
hp_vec.push_back(_hp);
diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h
index e3ea41ba8..6acc9fb40 100644
--- a/src/live_effects/lpe-fillet-chamfer.h
+++ b/src/live_effects/lpe-fillet-chamfer.h
@@ -40,7 +40,6 @@ public:
virtual std::vector<Geom::Path>
doEffect_path(std::vector<Geom::Path> const &path_in);
virtual void doOnApply(SPLPEItem const *lpeItem);
- virtual void adjustForNewPath(std::vector<Geom::Path> const &path_in);
virtual Gtk::Widget *newWidget();
void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec);
void updateSatelliteType(Geom::SatelliteType satellitetype);
@@ -68,7 +67,6 @@ private:
ScalarParam helper_size;
Geom::Pointwise *pointwise;
- double segment_size;
Geom::PathVector _hp;
LPEFilletChamfer(const LPEFilletChamfer &);
diff --git a/src/ui/tool/multi-path-manipulator.cpp b/src/ui/tool/multi-path-manipulator.cpp
index f53cef5f4..8a8e4cb8a 100644
--- a/src/ui/tool/multi-path-manipulator.cpp
+++ b/src/ui/tool/multi-path-manipulator.cpp
@@ -330,20 +330,20 @@ void MultiPathManipulator::insertNodes()
{
if (_selection.empty()) return;
invokeForAll(&PathManipulator::insertNodes);
- _done(_("Add nodes"));
+ _done(_("Add nodes"), true);
}
void MultiPathManipulator::insertNodesAtExtrema(ExtremumType extremum)
{
if (_selection.empty()) return;
invokeForAll(&PathManipulator::insertNodeAtExtremum, extremum);
- _done(_("Add extremum nodes"));
+ _done(_("Add extremum nodes"), true);
}
void MultiPathManipulator::duplicateNodes()
{
if (_selection.empty()) return;
invokeForAll(&PathManipulator::duplicateNodes);
- _done(_("Duplicate nodes"));
+ _done(_("Duplicate nodes"), true);
}
void MultiPathManipulator::joinNodes()
@@ -483,10 +483,10 @@ void MultiPathManipulator::reverseSubpaths()
{
if (_selection.empty()) {
invokeForAll(&PathManipulator::reverseSubpaths, false);
- _done("Reverse subpaths");
+ _done("Reverse subpaths", true);
} else {
invokeForAll(&PathManipulator::reverseSubpaths, true);
- _done("Reverse selected subpaths");
+ _done("Reverse selected subpaths", true);
}
}
diff --git a/src/ui/tool/path-manipulator.cpp b/src/ui/tool/path-manipulator.cpp
index dbae69f2c..d50c3057b 100644
--- a/src/ui/tool/path-manipulator.cpp
+++ b/src/ui/tool/path-manipulator.cpp
@@ -1356,13 +1356,6 @@ void PathManipulator::_createGeometryFromControlPoints(bool alert_LPE)
lpe_pwr->adjustForNewPath(pathv);
}
}
- thisEffect = _path->getPathEffectOfType(Inkscape::LivePathEffect::FILLET_CHAMFER);
- if(thisEffect){
- LivePathEffect::LPEFilletChamfer *lpe_fll = dynamic_cast<LivePathEffect::LPEFilletChamfer*>(thisEffect->getLPEObj()->get_lpe());
- if (lpe_fll) {
- lpe_fll->adjustForNewPath(pathv);
- }
- }
}
}