summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2015-03-03 22:54:42 +0000
committerJabiertxof <jtx@jtx.marker.es>2015-03-03 22:54:42 +0000
commit60327dd47f6bbbb0d30c13c905117bd8b3be5e5d (patch)
tree9f8299ca225cab90d844230b54889bae603b2a69 /src
parentupdate to trunk (diff)
downloadinkscape-60327dd47f6bbbb0d30c13c905117bd8b3be5e5d.tar.gz
inkscape-60327dd47f6bbbb0d30c13c905117bd8b3be5e5d.zip
added helper paths and fixed some bugs
(bzr r13645.1.30)
Diffstat (limited to 'src')
-rw-r--r--src/2geom/pointwise.cpp4
-rw-r--r--src/2geom/pointwise.h2
-rw-r--r--src/2geom/satellite.cpp9
-rw-r--r--src/2geom/satellite.h1
-rw-r--r--src/live_effects/lpe-fillet-chamfer.cpp66
-rw-r--r--src/live_effects/lpe-fillet-chamfer.h1
-rw-r--r--src/live_effects/parameter/satellitepairarray.cpp87
-rw-r--r--src/live_effects/parameter/satellitepairarray.h9
8 files changed, 134 insertions, 45 deletions
diff --git a/src/2geom/pointwise.cpp b/src/2geom/pointwise.cpp
index 3c359eddc..0115ea103 100644
--- a/src/2geom/pointwise.cpp
+++ b/src/2geom/pointwise.cpp
@@ -124,7 +124,7 @@ Pointwise::findSatellites(int A, int B) const
}
std::vector<Satellite>
-Pointwise::findClosingSatellites(int A, int B) const
+Pointwise::findClosingSatellites(int A) const
{
std::vector<Satellite> ret;
bool finded = false;
@@ -151,7 +151,7 @@ Pointwise::findPeviousSatellites(int A, int B) const
if(!_satellites[i].second.getIsStart()){
ret = findSatellites(_satellites[i-1].first, B);
} else {
- ret = findClosingSatellites(_satellites[i].first, B);
+ ret = findClosingSatellites(_satellites[i].first);
}
}
}
diff --git a/src/2geom/pointwise.h b/src/2geom/pointwise.h
index c7426dc9d..aa907d498 100644
--- a/src/2geom/pointwise.h
+++ b/src/2geom/pointwise.h
@@ -68,7 +68,7 @@ class Pointwise
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<Satellite> findClosingSatellites(int A) 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 9c253523e..c216595dc 100644
--- a/src/2geom/satellite.cpp
+++ b/src/2geom/satellite.cpp
@@ -117,6 +117,15 @@ Satellite::getTime(Geom::D2<Geom::SBasis> d2_in){
return t;
}
+double
+Satellite::getSize(Geom::D2<Geom::SBasis> d2_in){
+ double s = getAmmount();
+ if(getIsTime()){
+ s = toSize(s, d2_in);
+ }
+ return s;
+}
+
Geom::Point
Satellite::getPosition(Geom::D2<Geom::SBasis> d2_in){
diff --git a/src/2geom/satellite.h b/src/2geom/satellite.h
index aa949a97c..48be13cc4 100644
--- a/src/2geom/satellite.h
+++ b/src/2geom/satellite.h
@@ -152,6 +152,7 @@ class Satellite
void setPosition(Geom::Point p, Geom::D2<Geom::SBasis> d2_in);
Geom::Point getPosition(Geom::D2<Geom::SBasis> curve);
+ double getSize(Geom::D2<Geom::SBasis> d2_in);
double getTime(Geom::D2<Geom::SBasis> d2_in);
double getOpositeTime(double A,Geom::D2<Geom::SBasis> SBasisCurve);
double toSize(double A,Geom::D2<Geom::SBasis> d2_in);
diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp
index 802340698..a8e2ea6b8 100644
--- a/src/live_effects/lpe-fillet-chamfer.cpp
+++ b/src/live_effects/lpe-fillet-chamfer.cpp
@@ -58,6 +58,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) :
use_knot_distance(_("Use knots distance instead radius"), _("Use knots distance instead radius"), "use_knot_distance", &wr, this, false),
hide_knots(_("Hide knots"), _("Hide knots"), "hide_knots", &wr, this, false),
ignore_radius_0(_("Ignore 0 radius knots"), _("Ignore 0 radius knots"), "ignore_radius_0", &wr, this, false),
+ helper_size(_("Helper size with direction:"), _("Helper size with direction"), "helper_size", &wr, this, 0),
pointwise()
{
registerParameter(&satellitepairarrayparam_values);
@@ -65,6 +66,7 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) :
registerParameter(&method);
registerParameter(&radius);
registerParameter(&chamfer_steps);
+ registerParameter(&helper_size);
registerParameter(&flexible);
registerParameter(&use_knot_distance);
registerParameter(&mirror_knots);
@@ -78,6 +80,9 @@ LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) :
chamfer_steps.param_set_range(1, 999);
chamfer_steps.param_set_increments(1, 1);
chamfer_steps.param_set_digits(0);
+ helper_size.param_set_range(0, infinity());
+ helper_size.param_set_increments(5, 5);
+ helper_size.param_set_digits(0);
}
LPEFilletChamfer::~LPEFilletChamfer() {}
@@ -126,8 +131,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem)
bool active = true;
bool hidden = false;
if (counter==0) {
- if (path_it->closed()) {
- } else {
+ if (!path_it->closed()) {
active = false;
}
}
@@ -179,27 +183,12 @@ Gtk::Widget *LPEFilletChamfer::newWidget()
Gtk::Entry *entryWidg = dynamic_cast<Gtk::Entry *>(childList[1]);
entryWidg->set_width_chars(6);
}
- /*} else if (param->param_key == "chamfer_steps") {
- Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast<Inkscape::UI::Widget::Scalar *>(widg));
- widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::chamferSubdivisions));
- widg = widgRegistered;
- if (widg) {
- Gtk::HBox *scalarParameter = dynamic_cast<Gtk::HBox *>(widg);
- std::vector<Gtk::Widget *> childList = scalarParameter->get_children();
- Gtk::Entry *entryWidg = dynamic_cast<Gtk::Entry *>(childList[1]);
- entryWidg->set_width_chars(3);
- }
-
} else if (param->param_key == "helper_size") {
Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast<Inkscape::UI::Widget::Scalar *>(widg));
widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEFilletChamfer::refreshKnots));
- */
} else if (param->param_key == "only_selected") {
Gtk::manage(widg);
- }/* else if (param->param_key == "ignore_radius_0") {
- Gtk::manage(widg);
}
- */
Glib::ustring *tip = param->param_getTooltip();
if (widg) {
vbox->pack_start(*widg, true, true, 2);
@@ -211,7 +200,6 @@ Gtk::Widget *LPEFilletChamfer::newWidget()
}
}
}
-
++it;
}
@@ -285,24 +273,25 @@ double LPEFilletChamfer::len_to_rad(double A, std::pair<int,Geom::Satellite> sa
double LPEFilletChamfer::rad_to_len(double A, std::pair<int,Geom::Satellite> satellite)
{
double len = 0;
+ std::cout << A << "A\n";
Piecewise<Geom::D2<Geom::SBasis> > pwd2 = pointwise->getPwd2();
boost::optional<Geom::D2<Geom::SBasis> > d2_in = pointwise->getCurveIn(satellite);
if(d2_in){
+ std::cout << satellite.first << "satellite.first\n";
+ std::cout << "d2in\n";
Geom::D2<Geom::SBasis> d2_out = pwd2[satellite.first];
- Piecewise<D2<SBasis> > offset_curve0 = Piecewise<D2<SBasis> >(*d2_in)+rot90(unitVector(derivative((*d2_in))))*(A);
+ Piecewise<D2<SBasis> > offset_curve0 = Piecewise<D2<SBasis> >(*d2_in)+rot90(unitVector(derivative(*d2_in)))*(A);
Piecewise<D2<SBasis> > offset_curve1 = Piecewise<D2<SBasis> >(d2_out)+rot90(unitVector(derivative(d2_out)))*(A);
Geom::Path p0 = path_from_piecewise(offset_curve0, 0.1)[0];
Geom::Path p1 = path_from_piecewise(offset_curve1, 0.1)[0];
Geom::Crossings cs = Geom::crossings(p0, p1);
if(cs.size() > 0){
Point cp =p0(cs[0].ta);
+ std::cout << cp << "cp\n";
double p0pt = nearest_point(cp, d2_out);
len = satellite.second.toSize(p0pt,d2_out);
- } else {
- if(A < 0){
- len = rad_to_len(A * -1, satellite);
- }
}
+ std::cout << len << "len\n";
}
return len;
}
@@ -328,21 +317,27 @@ void LPEFilletChamfer::updateFillet()
std::vector<std::pair<int,Geom::Satellite> > satellites = pointwise->getSatellites();
Piecewise<D2<SBasis> > pwd2 = pointwise->getPwd2();
for (std::vector<std::pair<int,Geom::Satellite> >::iterator it = satellites.begin(); it != satellites.end(); ++it) {
+ if(pointwise->findClosingSatellites(it->first).size() == 0 && it->second.getIsStart()){
+ it->second.setAmmount(0);
+ continue;
+ }
if(ignore_radius_0 && it->second.getAmmount() == 0){
continue;
}
if(only_selected){
Geom::Point satPoint = pwd2.valueAt(it->first);
if(isNodePointSelected(satPoint)){
- it->second.setAmmount(power);
- }
- if(!use_knot_distance && !flexible){
- it->second.setAmmount(rad_to_len(power,*it));
+ if(!use_knot_distance && !flexible){
+ it->second.setAmmount(rad_to_len(power,*it));
+ } else {
+ it->second.setAmmount(power);
+ }
}
} else {
- it->second.setAmmount(power);
if(!use_knot_distance && !flexible){
it->second.setAmmount(rad_to_len(power,*it));
+ } else {
+ it->second.setAmmount(power);
}
}
}
@@ -384,12 +379,14 @@ void LPEFilletChamfer::doBeforeEffect(SPLPEItem const *lpeItem)
PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(c->get_pathvector());
Piecewise<D2<SBasis> > pwd2_in = paths_to_pw(pathv_to_linear_and_cubic_beziers(original_pathv));
pwd2_in = remove_short_cuts(pwd2_in, 0.01);
- //wating to recalculate
- //recalculate_controlpoints_for_new_pwd2(pwd2_in);
std::vector<std::pair<int,Geom::Satellite> > satellites = satellitepairarrayparam_values.data();
- pointwise->setPwd2(pwd2_in);
- pointwise->setSatellites(satellites);
+ pointwise = new Pointwise(pwd2_in,satellites);
satellitepairarrayparam_values.set_pointwise(pointwise);
+ if(hide_knots){
+ satellitepairarrayparam_values.set_helper_size(0);
+ } else {
+ satellitepairarrayparam_values.set_helper_size(helper_size);
+ }
bool changed = false;
bool refresh = false;
for (std::vector<std::pair<int,Geom::Satellite> >::iterator it = satellites.begin(); it != satellites.end(); ++it) {
@@ -491,10 +488,7 @@ LPEFilletChamfer::doEffect_path(std::vector<Geom::Path> const &path_in)
}
bool last = curve_it2 == curve_endit;
- double s = satellite.getAmmount();
- if(satellite.getIsTime()){
- s = satellite.toSize(s, curve_it2Fixed->toSBasis());
- }
+ double s = satellite.getSize(curve_it2Fixed->toSBasis());
double time1 = satellite.getOpositeTime(s,(*curve_it1).toSBasis());
double time2 = satellite.getTime(curve_it2Fixed->toSBasis());
if(time1 <= time0){
diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h
index 44c8b113f..c194d2edd 100644
--- a/src/live_effects/lpe-fillet-chamfer.h
+++ b/src/live_effects/lpe-fillet-chamfer.h
@@ -62,6 +62,7 @@ private:
BoolParam use_knot_distance;
BoolParam hide_knots;
BoolParam ignore_radius_0;
+ ScalarParam helper_size;
Geom::Pointwise *pointwise;
diff --git a/src/live_effects/parameter/satellitepairarray.cpp b/src/live_effects/parameter/satellitepairarray.cpp
index beda9ecbf..72a666dc2 100644
--- a/src/live_effects/parameter/satellitepairarray.cpp
+++ b/src/live_effects/parameter/satellitepairarray.cpp
@@ -31,6 +31,14 @@ SatellitePairArrayParam::SatellitePairArrayParam(
knot_shape = SP_KNOT_SHAPE_DIAMOND;
knot_mode = SP_KNOT_MODE_XOR;
knot_color = 0x00ff0000;
+ /*
+ std::vector<std::pair<int,Geom::Satellite> > satellites;
+ Geom::Path path;
+ path.start(Geom::Point(0,0));
+ path.appendNew<Geom::LineSegment>(Geom::Point(0,1));
+ last_pointwise = new Pointwise(path.toPwSb(),satellites);
+ */
+ last_pointwise = NULL;
}
SatellitePairArrayParam::~SatellitePairArrayParam() {}
@@ -49,6 +57,74 @@ void SatellitePairArrayParam::set_pointwise(Geom::Pointwise *pointwise)
last_pointwise = pointwise;
}
+void SatellitePairArrayParam::set_helper_size(int hs)
+{
+ helper_size = hs;
+ updateCanvasIndicators();
+}
+
+void SatellitePairArrayParam::updateCanvasIndicators()
+{
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = last_pointwise->getPwd2();
+ hp.clear();
+ bool mirrorPass = false;
+ for (unsigned int i = 0; i < _vector.size(); ++i) {
+ if(!_vector[i].second.getActive() || !_vector[i].second.getHidden()){
+ continue;
+ }
+ double pos = 0;
+ if(pwd2.size() <= _vector[i].first){
+ break;
+ }
+ Geom::D2<Geom::SBasis> d2 = pwd2[_vector[i].first];
+ if(mirrorPass == true){
+ double size = _vector[i].second.getSize(pwd2[_vector[i].first]);
+ boost::optional<Geom::D2<Geom::SBasis> > curve_in = last_pointwise->getCurveIn(_vector[i]);
+ if(curve_in){
+ d2 = *curve_in;
+ pos = _vector[i].second.getOpositeTime(size,*curve_in);
+ }
+ } else {
+ pos = _vector[i].second.getTime(pwd2[_vector[i].first]);
+ }
+ if (pos == 0) {
+ continue;
+ }
+ Geom::Point ptA = d2.valueAt(pos);
+ Geom::Point derivA = unit_vector(derivative(d2).valueAt(pos));
+ Geom::Rotate rot(Geom::Rotate::from_degrees(-90));
+ derivA = derivA * rot;
+ Geom::Point C = ptA - derivA * helper_size;
+ Geom::Point D = ptA + derivA * helper_size;
+ Geom::Ray ray1(C, 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(mirrorPass == true){
+ aff *= Geom::Rotate(ray1.angle() - deg_to_rad(90));
+ } else {
+ aff *= Geom::Rotate(ray1.angle() - deg_to_rad(270));
+ }
+ pathv *= aff;
+ pathv += d2.valueAt(pos);
+ hp.push_back(pathv[0]);
+ hp.push_back(pathv[1]);
+ if(_vector[i].second.getHasMirror() && mirrorPass == false){
+ mirrorPass = true;
+ i--;
+ } else {
+ mirrorPass = false;
+ }
+ }
+}
+
+void SatellitePairArrayParam::addCanvasIndicators(
+ SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
+{
+ hp_vec.push_back(hp);
+}
+
void SatellitePairArrayParam::addKnotHolderEntities(KnotHolder *knotholder,
SPDesktop *desktop,
SPItem *item)
@@ -103,6 +179,9 @@ void SatellitePairArrayParamKnotHolderEntity::knot_set(Point const &p,
if( _index >= _pparam->_vector.size()){
index = _index-_pparam->_vector.size();
}
+ if( _pparam->last_pointwise == NULL){
+ return;
+ }
std::pair<int,Geom::Satellite> satellite = _pparam->_vector.at(index);
Geom::Pointwise* pointwise = _pparam->last_pointwise;
Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = pointwise->getPwd2();
@@ -143,16 +222,16 @@ SatellitePairArrayParamKnotHolderEntity::knot_get() const
index = _index-_pparam->_vector.size();
}
std::pair<int,Geom::Satellite> satellite = _pparam->_vector.at(index);
+ if( _pparam->last_pointwise == NULL){
+ return Geom::Point(0,0);
+ }
Geom::Pointwise* pointwise = _pparam->last_pointwise;
Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = pointwise->getPwd2();
if( _index >= _pparam->_vector.size()){
tmpPoint = satellite.second.getPosition(pwd2[satellite.first]);
boost::optional<Geom::D2<Geom::SBasis> > d2_in = pointwise->getCurveIn(satellite);
if(d2_in){
- double s = satellite.second.getAmmount();
- if(satellite.second.getIsTime()){
- s = satellite.second.toSize(s, pwd2[satellite.first]);
- }
+ double s = satellite.second.getSize(pwd2[satellite.first]);
double t = satellite.second.getOpositeTime(s,*d2_in);
if(t > 1){
t = 1;
diff --git a/src/live_effects/parameter/satellitepairarray.h b/src/live_effects/parameter/satellitepairarray.h
index dde844fd1..1ecc1fee6 100644
--- a/src/live_effects/parameter/satellitepairarray.h
+++ b/src/live_effects/parameter/satellitepairarray.h
@@ -44,11 +44,14 @@ public:
void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode,
guint32 color);
+ virtual void set_helper_size(int hs);
+ virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
+ virtual void addKnotHolderEntitieMirrored(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, int i);
+ virtual void addCanvasIndicators(SPLPEItem const *lpeitem,std::vector<Geom::PathVector> &hp_vec);
virtual bool providesKnotHolderEntities() const {
return true;
}
- virtual void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
- virtual void addKnotHolderEntitieMirrored(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item, int i);
+ virtual void updateCanvasIndicators();
void set_pointwise(Geom::Pointwise *pointwise);
friend class SatellitePairArrayParamKnotHolderEntity;
@@ -59,6 +62,8 @@ private:
SPKnotShapeType knot_shape;
SPKnotModeType knot_mode;
guint32 knot_color;
+ Geom::PathVector hp;
+ int helper_size;
Geom::Pointwise *last_pointwise;