summaryrefslogtreecommitdiffstats
path: root/src/ui/tools/pen-tool.cpp
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-11-28 21:47:59 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2017-11-28 21:47:59 +0000
commitd383c6fe801cf851bffb7927d508b5251e19522c (patch)
tree698edd9475bd9e6b8cecbb26179a3755c5de5514 /src/ui/tools/pen-tool.cpp
parentWorking on continuous paths (diff)
downloadinkscape-d383c6fe801cf851bffb7927d508b5251e19522c.tar.gz
inkscape-d383c6fe801cf851bffb7927d508b5251e19522c.zip
Working on BSPline interpolator
Diffstat (limited to 'src/ui/tools/pen-tool.cpp')
-rw-r--r--src/ui/tools/pen-tool.cpp152
1 files changed, 61 insertions, 91 deletions
diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp
index 16cdf63b5..f42af8bb6 100644
--- a/src/ui/tools/pen-tool.cpp
+++ b/src/ui/tools/pen-tool.cpp
@@ -422,8 +422,9 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
case PenTool::STOP:
// This is allowed, if we just canceled curve
case PenTool::POINT:
+ this->setPolylineMode();
+ this->_bsplineSpiroColor();
if (this->npoints == 0) {
- this->_bsplineSpiroColor();
Geom::Point p;
if ((bevent.state & GDK_CONTROL_MASK) && (this->polylines_only || this->polylines_paraxial)) {
p = event_dt;
@@ -444,7 +445,13 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
// Set start anchor
this->sa = anchor;
- if(anchor){
+ if (anchor) {
+ //Put the start overwrite curve always on the same direction
+ if (anchor->start) {
+ this->sa_overwrited = this->sa->curve->create_reverse();
+ } else {
+ this->sa_overwrited = this->sa->curve->copy();
+ }
this->_bsplineSpiroStartAnchor(bevent.state & GDK_SHIFT_MASK);
}
if (anchor && (!this->hasWaitingLPE()|| this->bspline || this->spiro)) {
@@ -473,7 +480,6 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
}
this->_setInitialPoint(p);
} else {
-
// Set end anchor
this->ea = anchor;
Geom::Point p;
@@ -734,27 +740,30 @@ bool PenTool::_handleButtonRelease(GdkEventButton const &revent) {
case PenTool::MODE_CLICK:
switch (this->state) {
case PenTool::POINT:
- if ( this->npoints == 0 ) {
- // Start new thread only with button release
- this->_bsplineSpiroColor();
- if (anchor) {
- p = anchor->dp;
- }
- this->sa = anchor;
- // continue the existing curve
- if (anchor) {
- if(this->bspline || this->spiro){
- this->_bsplineSpiroStartAnchor(revent.state & GDK_SHIFT_MASK);;
- }
- }
- this->_setInitialPoint(p);
- } else {
+// if ( this->npoints == 0 ) {
+// // Start new thread only with button release
+// this->_bsplineSpiroColor();
+// if (anchor) {
+// p = anchor->dp;
+// this->sa = anchor;
+// //Put the start overwrite curve always on the same direction
+// if (anchor->start) {
+// this->sa_overwrited = this->sa->curve->create_reverse();
+// } else {
+// this->sa_overwrited = this->sa->curve->copy();
+// }
+// if(this->bspline || this->spiro){
+// this->_bsplineSpiroStartAnchor(revent.state & GDK_SHIFT_MASK);;
+// }
+// }
+// this->_setInitialPoint(p);
+// } else {
// Set end anchor here
this->ea = anchor;
if (anchor) {
p = anchor->dp;
}
- }
+ //}
this->state = PenTool::CONTROL;
break;
case PenTool::CONTROL:
@@ -1264,6 +1273,8 @@ void PenTool::_resetColors() {
}
this->sa = NULL;
this->ea = NULL;
+ this->sa_overwrited->reset();
+
this->npoints = 0;
this->red_curve_is_valid = false;
}
@@ -1415,11 +1426,7 @@ void PenTool::_bsplineSpiroStartAnchor(bool shift)
this->spiro = false;
}
if(!this->spiro && !this->bspline){
- SPCurve *tmp_curve = this->sa->curve->copy();
- if (this->sa->start) {
- tmp_curve = tmp_curve ->create_reverse();
- }
- this->overwrite_curve = tmp_curve ;
+ _bsplineSpiroColor();
return;
}
if(shift){
@@ -1433,14 +1440,10 @@ void PenTool::_bsplineSpiroStartAnchorOn()
{
using Geom::X;
using Geom::Y;
- SPCurve *tmp_curve = this->sa->curve->copy();
- if (this->sa->start) {
- tmp_curve = tmp_curve ->create_reverse();
- }
- Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmp_curve ->last_segment());
+ Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*this->sa_overwrited ->last_segment());
SPCurve *last_segment = new SPCurve();
- Geom::Point point_a = tmp_curve->last_segment()->initialPoint();
- Geom::Point point_d = *tmp_curve->last_point();
+ Geom::Point point_a = this->sa_overwrited->last_segment()->initialPoint();
+ Geom::Point point_d = *this->sa_overwrited->last_point();
Geom::Point point_c = point_d + (1./3)*(point_a - point_d);
point_c = Geom::Point(point_c[X] + HANDLE_CUBIC_GAP, point_c[Y] + HANDLE_CUBIC_GAP);
if(cubic){
@@ -1450,43 +1453,34 @@ void PenTool::_bsplineSpiroStartAnchorOn()
last_segment->moveto(point_a);
last_segment->curveto(point_a,point_c,point_d);
}
- if( tmp_curve ->get_segment_count() == 1){
- tmp_curve = last_segment;
+ if( this->sa_overwrited->get_segment_count() == 1){
+ this->sa_overwrited = last_segment->copy();
}else{
//we eliminate the last segment
- tmp_curve ->backspace();
+ this->sa_overwrited->backspace();
//and we add it again with the recreation
- tmp_curve ->append_continuous(last_segment, 0.0625);
+ this->sa_overwrited->append_continuous(last_segment, 0.0625);
}
- if (this->sa->start) {
- tmp_curve = tmp_curve ->create_reverse();
- }
- this->overwrite_curve = tmp_curve ;
+ last_segment->unref();
}
void PenTool::_bsplineSpiroStartAnchorOff()
{
- SPCurve *tmp_curve = this->sa->curve->copy();
- if(this->sa->start)
- tmp_curve = tmp_curve ->create_reverse();
- Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmp_curve ->last_segment());
+ Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*this->sa_overwrited->last_segment());
if(cubic){
SPCurve *last_segment = new SPCurve();
last_segment->moveto((*cubic)[0]);
last_segment->curveto((*cubic)[1],(*cubic)[3],(*cubic)[3]);
- if( tmp_curve ->get_segment_count() == 1){
- tmp_curve = last_segment;
+ if( this->sa_overwrited->get_segment_count() == 1){
+ this->sa_overwrited = last_segment->copy();
}else{
//we eliminate the last segment
- tmp_curve ->backspace();
+ this->sa_overwrited->backspace();
//and we add it again with the recreation
- tmp_curve ->append_continuous(last_segment, 0.0625);
+ this->sa_overwrited->append_continuous(last_segment, 0.0625);
}
+ last_segment->unref();
}
- if (this->sa->start) {
- tmp_curve = tmp_curve ->create_reverse();
- }
- this->overwrite_curve = tmp_curve;
}
void PenTool::_bsplineSpiroMotion(guint const state){
@@ -1510,10 +1504,7 @@ void PenTool::_bsplineSpiroMotion(guint const state){
} else if (!this->green_curve->is_unset()){
tmp_curve = this->green_curve->copy();
} else {
- tmp_curve = this->overwrite_curve->copy();
- if(this->sa->start) {
- tmp_curve = tmp_curve ->create_reverse();
- }
+ tmp_curve = this->sa_overwrited->copy();
}
if ((state & GDK_MOD1_MASK ) && previous != Geom::Point(0,0)) { //ALT drag
this->p[0] = this->p[0] + (this->p[3] - previous);
@@ -1550,11 +1541,7 @@ void PenTool::_bsplineSpiroMotion(guint const state){
}
cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmp_curve ->last_segment());
if (this->sa && this->green_curve->is_unset()) {
- if(this->sa->start) {
- this->overwrite_curve = tmp_curve->copy()->create_reverse();
- } else {
- this->overwrite_curve = tmp_curve->copy();
- }
+ this->sa_overwrited = tmp_curve->copy();
}
if (!this->green_bpaths.empty()) {
this->green_curve = tmp_curve->copy();
@@ -1627,19 +1614,13 @@ void PenTool::_bsplineSpiroEndAnchorOn()
SPCurve *tmp_curve;
SPCurve *last_segment = new SPCurve();
Geom::Point point_c(0,0);
- bool reverse = false;
if( this->green_anchor && this->green_anchor->active ){
tmp_curve = this->green_curve->create_reverse();
if(this->green_curve->get_segment_count()==0){
return;
}
- reverse = true;
} else if(this->sa){
- tmp_curve = this->overwrite_curve->copy();
- if(!this->sa->start){
- tmp_curve = tmp_curve ->create_reverse();
- reverse = true;
- }
+ tmp_curve = this->sa_overwrited->copy()->create_reverse();
}else{
return;
}
@@ -1665,17 +1646,16 @@ void PenTool::_bsplineSpiroEndAnchorOn()
//and we add it again with the recreation
tmp_curve ->append_continuous(last_segment, 0.0625);
}
- if (reverse) {
- tmp_curve = tmp_curve ->create_reverse();
- }
+ tmp_curve = tmp_curve ->create_reverse();
if( this->green_anchor && this->green_anchor->active )
{
this->green_curve->reset();
- this->green_curve = tmp_curve ;
+ this->green_curve = tmp_curve->copy();
}else{
- this->overwrite_curve->reset();
- this->overwrite_curve = tmp_curve ;
+ this->sa_overwrited->reset();
+ this->sa_overwrited = tmp_curve->copy();
}
+ tmp_curve->unref();
}
void PenTool::_bsplineSpiroEndAnchorOff()
@@ -1683,20 +1663,14 @@ void PenTool::_bsplineSpiroEndAnchorOff()
SPCurve *tmp_curve;
SPCurve *last_segment = new SPCurve();
- bool reverse = false;
this->p[2] = this->p[3];
if( this->green_anchor && this->green_anchor->active ){
tmp_curve = this->green_curve->create_reverse();
if(this->green_curve->get_segment_count()==0){
return;
}
- reverse = true;
} else if(this->sa){
- tmp_curve = this->overwrite_curve->copy();
- if(!this->sa->start){
- tmp_curve = tmp_curve ->create_reverse();
- reverse = true;
- }
+ tmp_curve = this->sa_overwrited->copy()->create_reverse();
}else{
return;
}
@@ -1716,17 +1690,17 @@ void PenTool::_bsplineSpiroEndAnchorOff()
//and we add it again with the recreation
tmp_curve ->append_continuous(last_segment, 0.0625);
}
- if (reverse) {
- tmp_curve = tmp_curve ->create_reverse();
- }
+ tmp_curve = tmp_curve ->create_reverse();
+
if( this->green_anchor && this->green_anchor->active )
{
this->green_curve->reset();
- this->green_curve = tmp_curve ;
+ this->green_curve = tmp_curve->copy();
}else{
- this->overwrite_curve->reset();
- this->overwrite_curve = tmp_curve ;
+ this->sa_overwrited->reset();
+ this->sa_overwrited = tmp_curve->copy();
}
+ tmp_curve->unref();
}
//prepares the curves for its transformation into BSpline curve.
@@ -1740,10 +1714,7 @@ void PenTool::_bsplineSpiroBuild()
SPCurve *curve = new SPCurve();
//If we continuate the existing curve we add it at the start
if(this->sa && !this->sa->curve->is_unset()){
- curve = this->overwrite_curve->copy();
- if (this->sa->start) {
- curve = curve->create_reverse();
- }
+ curve = this->sa_overwrited->copy();
}
if (!this->green_curve->is_unset()){
@@ -2038,7 +2009,6 @@ void PenTool::_finish(gboolean const closed) {
// cancelate line without a created segment
this->red_curve->reset();
spdc_concat_colors_and_flush(this, closed);
- this->overwrite_curve = NULL;
this->sa = NULL;
this->ea = NULL;