From d383c6fe801cf851bffb7927d508b5251e19522c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Tue, 28 Nov 2017 22:47:59 +0100 Subject: Working on BSPline interpolator --- src/ui/tools/pen-tool.cpp | 152 +++++++++++++++++++--------------------------- 1 file changed, 61 insertions(+), 91 deletions(-) (limited to 'src/ui/tools/pen-tool.cpp') 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(&*tmp_curve ->last_segment()); + Geom::CubicBezier const * cubic = dynamic_cast(&*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(&*tmp_curve ->last_segment()); + Geom::CubicBezier const * cubic = dynamic_cast(&*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(&*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; -- cgit v1.2.3 From c1bf7779c6a607c29fb6cca06e39d183e4de31c7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Fri, 1 Dec 2017 22:31:36 +0100 Subject: Cleaninng --- src/ui/tools/pen-tool.cpp | 152 +++++++++++++++++++++++++++------------------- 1 file changed, 91 insertions(+), 61 deletions(-) (limited to 'src/ui/tools/pen-tool.cpp') diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index f42af8bb6..16cdf63b5 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -422,9 +422,8 @@ 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; @@ -445,13 +444,7 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) { // Set start anchor this->sa = 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(); - } + if(anchor){ this->_bsplineSpiroStartAnchor(bevent.state & GDK_SHIFT_MASK); } if (anchor && (!this->hasWaitingLPE()|| this->bspline || this->spiro)) { @@ -480,6 +473,7 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) { } this->_setInitialPoint(p); } else { + // Set end anchor this->ea = anchor; Geom::Point p; @@ -740,30 +734,27 @@ 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; -// //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 { + 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 { // Set end anchor here this->ea = anchor; if (anchor) { p = anchor->dp; } - //} + } this->state = PenTool::CONTROL; break; case PenTool::CONTROL: @@ -1273,8 +1264,6 @@ void PenTool::_resetColors() { } this->sa = NULL; this->ea = NULL; - this->sa_overwrited->reset(); - this->npoints = 0; this->red_curve_is_valid = false; } @@ -1426,7 +1415,11 @@ void PenTool::_bsplineSpiroStartAnchor(bool shift) this->spiro = false; } if(!this->spiro && !this->bspline){ - _bsplineSpiroColor(); + SPCurve *tmp_curve = this->sa->curve->copy(); + if (this->sa->start) { + tmp_curve = tmp_curve ->create_reverse(); + } + this->overwrite_curve = tmp_curve ; return; } if(shift){ @@ -1440,10 +1433,14 @@ void PenTool::_bsplineSpiroStartAnchorOn() { using Geom::X; using Geom::Y; - Geom::CubicBezier const * cubic = dynamic_cast(&*this->sa_overwrited ->last_segment()); + SPCurve *tmp_curve = this->sa->curve->copy(); + if (this->sa->start) { + tmp_curve = tmp_curve ->create_reverse(); + } + Geom::CubicBezier const * cubic = dynamic_cast(&*tmp_curve ->last_segment()); SPCurve *last_segment = new SPCurve(); - Geom::Point point_a = this->sa_overwrited->last_segment()->initialPoint(); - Geom::Point point_d = *this->sa_overwrited->last_point(); + Geom::Point point_a = tmp_curve->last_segment()->initialPoint(); + Geom::Point point_d = *tmp_curve->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){ @@ -1453,34 +1450,43 @@ void PenTool::_bsplineSpiroStartAnchorOn() last_segment->moveto(point_a); last_segment->curveto(point_a,point_c,point_d); } - if( this->sa_overwrited->get_segment_count() == 1){ - this->sa_overwrited = last_segment->copy(); + if( tmp_curve ->get_segment_count() == 1){ + tmp_curve = last_segment; }else{ //we eliminate the last segment - this->sa_overwrited->backspace(); + tmp_curve ->backspace(); //and we add it again with the recreation - this->sa_overwrited->append_continuous(last_segment, 0.0625); + tmp_curve ->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::_bsplineSpiroStartAnchorOff() { - Geom::CubicBezier const * cubic = dynamic_cast(&*this->sa_overwrited->last_segment()); + SPCurve *tmp_curve = this->sa->curve->copy(); + if(this->sa->start) + tmp_curve = tmp_curve ->create_reverse(); + Geom::CubicBezier const * cubic = dynamic_cast(&*tmp_curve ->last_segment()); if(cubic){ SPCurve *last_segment = new SPCurve(); last_segment->moveto((*cubic)[0]); last_segment->curveto((*cubic)[1],(*cubic)[3],(*cubic)[3]); - if( this->sa_overwrited->get_segment_count() == 1){ - this->sa_overwrited = last_segment->copy(); + if( tmp_curve ->get_segment_count() == 1){ + tmp_curve = last_segment; }else{ //we eliminate the last segment - this->sa_overwrited->backspace(); + tmp_curve ->backspace(); //and we add it again with the recreation - this->sa_overwrited->append_continuous(last_segment, 0.0625); + tmp_curve ->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){ @@ -1504,7 +1510,10 @@ void PenTool::_bsplineSpiroMotion(guint const state){ } else if (!this->green_curve->is_unset()){ tmp_curve = this->green_curve->copy(); } else { - tmp_curve = this->sa_overwrited->copy(); + tmp_curve = this->overwrite_curve->copy(); + if(this->sa->start) { + tmp_curve = tmp_curve ->create_reverse(); + } } if ((state & GDK_MOD1_MASK ) && previous != Geom::Point(0,0)) { //ALT drag this->p[0] = this->p[0] + (this->p[3] - previous); @@ -1541,7 +1550,11 @@ void PenTool::_bsplineSpiroMotion(guint const state){ } cubic = dynamic_cast(&*tmp_curve ->last_segment()); if (this->sa && this->green_curve->is_unset()) { - this->sa_overwrited = tmp_curve->copy(); + if(this->sa->start) { + this->overwrite_curve = tmp_curve->copy()->create_reverse(); + } else { + this->overwrite_curve = tmp_curve->copy(); + } } if (!this->green_bpaths.empty()) { this->green_curve = tmp_curve->copy(); @@ -1614,13 +1627,19 @@ 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->sa_overwrited->copy()->create_reverse(); + tmp_curve = this->overwrite_curve->copy(); + if(!this->sa->start){ + tmp_curve = tmp_curve ->create_reverse(); + reverse = true; + } }else{ return; } @@ -1646,16 +1665,17 @@ void PenTool::_bsplineSpiroEndAnchorOn() //and we add it again with the recreation tmp_curve ->append_continuous(last_segment, 0.0625); } - tmp_curve = tmp_curve ->create_reverse(); + if (reverse) { + tmp_curve = tmp_curve ->create_reverse(); + } if( this->green_anchor && this->green_anchor->active ) { this->green_curve->reset(); - this->green_curve = tmp_curve->copy(); + this->green_curve = tmp_curve ; }else{ - this->sa_overwrited->reset(); - this->sa_overwrited = tmp_curve->copy(); + this->overwrite_curve->reset(); + this->overwrite_curve = tmp_curve ; } - tmp_curve->unref(); } void PenTool::_bsplineSpiroEndAnchorOff() @@ -1663,14 +1683,20 @@ 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->sa_overwrited->copy()->create_reverse(); + tmp_curve = this->overwrite_curve->copy(); + if(!this->sa->start){ + tmp_curve = tmp_curve ->create_reverse(); + reverse = true; + } }else{ return; } @@ -1690,17 +1716,17 @@ void PenTool::_bsplineSpiroEndAnchorOff() //and we add it again with the recreation tmp_curve ->append_continuous(last_segment, 0.0625); } - tmp_curve = tmp_curve ->create_reverse(); - + if (reverse) { + tmp_curve = tmp_curve ->create_reverse(); + } if( this->green_anchor && this->green_anchor->active ) { this->green_curve->reset(); - this->green_curve = tmp_curve->copy(); + this->green_curve = tmp_curve ; }else{ - this->sa_overwrited->reset(); - this->sa_overwrited = tmp_curve->copy(); + this->overwrite_curve->reset(); + this->overwrite_curve = tmp_curve ; } - tmp_curve->unref(); } //prepares the curves for its transformation into BSpline curve. @@ -1714,7 +1740,10 @@ 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->sa_overwrited->copy(); + curve = this->overwrite_curve->copy(); + if (this->sa->start) { + curve = curve->create_reverse(); + } } if (!this->green_curve->is_unset()){ @@ -2009,6 +2038,7 @@ 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; -- cgit v1.2.3 From d9211f4fcd295d5a63bb713463487049311a24a2 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Tue, 26 Dec 2017 00:45:37 +0100 Subject: Fix start anchors --- src/ui/tools/pen-tool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/tools/pen-tool.cpp') diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index a42a3a07a..0616ba013 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -99,7 +99,7 @@ PenTool::PenTool() , cl1(NULL) , events_disabled(false) { - input_has_pressure = false; + tablet_enabled = false; } PenTool::PenTool(gchar const *const *cursor_shape) -- cgit v1.2.3