summaryrefslogtreecommitdiffstats
path: root/src/ui/tools/pen-tool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/tools/pen-tool.cpp')
-rw-r--r--src/ui/tools/pen-tool.cpp84
1 files changed, 36 insertions, 48 deletions
diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp
index 18af8e105..caf6faec2 100644
--- a/src/ui/tools/pen-tool.cpp
+++ b/src/ui/tools/pen-tool.cpp
@@ -32,8 +32,6 @@
#include "ui/draw-anchor.h"
#include "message-stack.h"
#include "message-context.h"
-#include "preferences.h"
-#include "sp-path.h"
#include "display/sp-canvas.h"
#include "display/curve.h"
#include "pixmaps/cursor-pen.xpm"
@@ -46,7 +44,6 @@
#include "ui/tools-switch.h"
#include "ui/control-manager.h"
// we include the necessary files for BSpline & Spiro
-#include "live_effects/effect.h"
#include "live_effects/lpeobject.h"
#include "live_effects/lpeobject-reference.h"
#include "live_effects/parameter/path.h"
@@ -54,25 +51,16 @@
#include "live_effects/lpe-spiro.h"
-#include <typeinfo>
-#include <2geom/pathvector.h>
-#include <2geom/affine.h>
#include <2geom/curves.h>
#include "helper/geom-nodetype.h"
-#include "helper/geom-curves.h"
// For handling un-continuous paths:
-#include "message-stack.h"
#include "inkscape.h"
-#include "desktop.h"
#include "live_effects/spiro.h"
#define INKSCAPE_LPE_BSPLINE_C
#include "live_effects/lpe-bspline.h"
-#include <2geom/nearest-time.h>
-
-#include "live_effects/effect.h"
using Inkscape::ControlManager;
@@ -379,7 +367,7 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
//with this we avoid creating a new point over the existing one
if(bevent.button != 3 && (this->spiro || this->bspline) && this->npoints > 0 && this->p[0] == this->p[3]){
- if( anchor && anchor == this->sa && this->green_curve->is_empty()){
+ if( anchor && anchor == this->sa && this->green_curve->is_unset()){
//remove the following line to avoid having one node on top of another
_finishSegment(event_dt, bevent.state);
_finish(true);
@@ -877,7 +865,7 @@ void PenTool::_redrawAll() {
this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data);
}
// one canvas bpath for all of green_curve
- SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve);
+ SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve, true);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvas_shape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(canvas_shape), 0, SP_WIND_RULE_NONZERO);
@@ -889,7 +877,7 @@ void PenTool::_redrawAll() {
this->red_curve->reset();
this->red_curve->moveto(this->p[0]);
this->red_curve->curveto(this->p[1], this->p[2], this->p[3]);
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve, true);
// handles
// hide the handlers in bspline and spiro modes
@@ -931,7 +919,7 @@ void PenTool::_lastpointMove(gdouble x, gdouble y) {
return;
// green
- if (!this->green_curve->is_empty()) {
+ if (!this->green_curve->is_unset()) {
this->green_curve->last_point_additive_move( Geom::Point(x,y) );
} else {
// start anchor too
@@ -959,7 +947,7 @@ void PenTool::_lastpointToCurve() {
this->p[1] = this->red_curve->last_segment()->initialPoint() + (1./3.)*(this->red_curve->last_segment()->finalPoint() - this->red_curve->last_segment()->initialPoint());
//modificate the last segment of the green curve so it creates the type of node we need
if (this->spiro||this->bspline) {
- if (!this->green_curve->is_empty()) {
+ if (!this->green_curve->is_unset()) {
Geom::Point A(0,0);
Geom::Point B(0,0);
Geom::Point C(0,0);
@@ -998,7 +986,7 @@ void PenTool::_lastpointToCurve() {
}
}
//if the last node is an union with another curve
- if (this->green_curve->is_empty() && this->sa && !this->sa->curve->is_empty()) {
+ if (this->green_curve->is_unset() && this->sa && !this->sa->curve->is_unset()) {
this->_bsplineSpiroStartAnchor(false);
}
}
@@ -1014,7 +1002,7 @@ void PenTool::_lastpointToLine() {
// modify the last segment of the green curve so the type of node we want is created.
if(this->spiro || this->bspline){
- if(!this->green_curve->is_empty()){
+ if(!this->green_curve->is_unset()){
Geom::Point A(0,0);
Geom::Point B(0,0);
Geom::Point C(0,0);
@@ -1045,7 +1033,7 @@ void PenTool::_lastpointToLine() {
}
}
// if the last node is an union with another curve
- if(this->green_curve->is_empty() && this->sa && !this->sa->curve->is_empty()){
+ if(this->green_curve->is_unset() && this->sa && !this->sa->curve->is_unset()){
this->_bsplineSpiroStartAnchor(true);
}
}
@@ -1224,7 +1212,7 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
// All this is needed to stop the last control
// point dispeating and stop making an n-1 shape.
Geom::Point const p(0, 0);
- if(this->red_curve->is_empty()) {
+ if(this->red_curve->is_unset()) {
this->red_curve->moveto(p);
}
this->_finishSegment(p, 0);
@@ -1245,7 +1233,7 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
case GDK_KEY_g:
case GDK_KEY_G:
if (MOD__SHIFT_ONLY(event)) {
- sp_selection_to_guides(this->desktop);
+ this->desktop->selection->toGuides();
ret = true;
}
break;
@@ -1263,10 +1251,10 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
void PenTool::_resetColors() {
// Red
this->red_curve->reset();
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL, true);
// Blue
this->blue_curve->reset();
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->blue_bpath), NULL);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->blue_bpath), NULL, true);
// Green
while (this->green_bpaths) {
sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data));
@@ -1289,7 +1277,7 @@ void PenTool::_setInitialPoint(Geom::Point const p) {
this->p[0] = p;
this->p[1] = p;
this->npoints = 2;
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL, true);
this->desktop->canvas->forceFullRedrawAfterInterruptions(5);
}
@@ -1355,7 +1343,7 @@ void PenTool::_bsplineSpiroColor()
this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data);
}
// one canvas bpath for all of green_curve
- SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve);
+ SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve, true);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvas_shape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(canvas_shape), 0, SP_WIND_RULE_NONZERO);
this->green_bpaths = g_slist_prepend(this->green_bpaths, canvas_shape);
@@ -1376,7 +1364,7 @@ void PenTool::_bsplineSpiro(bool shift)
void PenTool::_bsplineSpiroOn()
{
- if(!this->red_curve->is_empty()){
+ if(!this->red_curve->is_unset()){
using Geom::X;
using Geom::Y;
this->npoints = 5;
@@ -1389,7 +1377,7 @@ void PenTool::_bsplineSpiroOn()
void PenTool::_bsplineSpiroOff()
{
- if(!this->red_curve->is_empty()){
+ if(!this->red_curve->is_unset()){
this->npoints = 5;
this->p[0] = this->red_curve->first_segment()->initialPoint();
this->p[3] = this->red_curve->first_segment()->finalPoint();
@@ -1399,7 +1387,7 @@ void PenTool::_bsplineSpiroOff()
void PenTool::_bsplineSpiroStartAnchor(bool shift)
{
- if(this->sa->curve->is_empty()){
+ if(this->sa->curve->is_unset()){
return;
}
@@ -1509,18 +1497,18 @@ void PenTool::_bsplineSpiroMotion(bool shift){
}
using Geom::X;
using Geom::Y;
- if(this->red_curve->is_empty()) return;
+ if(this->red_curve->is_unset()) return;
this->npoints = 5;
SPCurve *tmp_curve = new SPCurve();
this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]);
this->p[2] = Geom::Point(this->p[2][X] + HANDLE_CUBIC_GAP,this->p[2][Y] + HANDLE_CUBIC_GAP);
- if(this->green_curve->is_empty() && !this->sa){
+ if(this->green_curve->is_unset() && !this->sa){
this->p[1] = this->p[0] + (1./3)*(this->p[3] - this->p[0]);
this->p[1] = Geom::Point(this->p[1][X] + HANDLE_CUBIC_GAP,this->p[1][Y] + HANDLE_CUBIC_GAP);
if(shift){
this->p[2] = this->p[3];
}
- }else if(!this->green_curve->is_empty()){
+ }else if(!this->green_curve->is_unset()){
tmp_curve = this->green_curve->copy();
}else{
tmp_curve = this->overwrite_curve->copy();
@@ -1528,7 +1516,7 @@ void PenTool::_bsplineSpiroMotion(bool shift){
tmp_curve = tmp_curve ->create_reverse();
}
- if(!tmp_curve ->is_empty()){
+ if(!tmp_curve ->is_unset()){
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmp_curve ->last_segment());
if(cubic){
if(this->bspline){
@@ -1560,7 +1548,7 @@ void PenTool::_bsplineSpiroMotion(bool shift){
}
}
- if(this->anchor_statusbar && !this->red_curve->is_empty()){
+ if(this->anchor_statusbar && !this->red_curve->is_unset()){
if(shift){
this->_bsplineSpiroEndAnchorOff();
}else{
@@ -1693,19 +1681,19 @@ void PenTool::_bsplineSpiroBuild()
//We create the base curve
SPCurve *curve = new SPCurve();
//If we continuate the existing curve we add it at the start
- if(this->sa && !this->sa->curve->is_empty()){
+ if(this->sa && !this->sa->curve->is_unset()){
curve = this->overwrite_curve->copy();
if (this->sa->start) {
curve = curve->create_reverse();
}
}
- if (!this->green_curve->is_empty()){
+ if (!this->green_curve->is_unset()){
curve->append_continuous(this->green_curve, 0.0625);
}
//and the red one
- if (!this->red_curve->is_empty()){
+ if (!this->red_curve->is_unset()){
this->red_curve->reset();
this->red_curve->moveto(this->p[0]);
if(this->anchor_statusbar && !this->sa && !(this->green_anchor && this->green_anchor->active)){
@@ -1713,11 +1701,11 @@ void PenTool::_bsplineSpiroBuild()
}else{
this->red_curve->curveto(this->p[1],this->p[2],this->p[3]);
}
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve, true);
curve->append_continuous(this->red_curve, 0.0625);
}
- if(!curve->is_empty()){
+ if(!curve->is_unset()){
// close the curve if the final points of the curve are close enough
if(Geom::are_near(curve->first_path()->initialPoint(), curve->last_path()->finalPoint())){
curve->closepath_current();
@@ -1734,7 +1722,7 @@ void PenTool::_bsplineSpiroBuild()
LivePathEffect::sp_spiro_do_effect(curve);
}
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->blue_bpath), curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->blue_bpath), curve, true);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->blue_bpath), this->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_item_show(this->blue_bpath);
curve->unref();
@@ -1790,7 +1778,7 @@ void PenTool::_setSubsequentPoint(Geom::Point const p, bool statusbar, guint sta
}
}
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve, true);
if (statusbar) {
gchar *message = is_curve ?
@@ -1830,7 +1818,7 @@ void PenTool::_setCtrl(Geom::Point const p, guint const state) {
this->red_curve->reset();
this->red_curve->moveto(this->p[0]);
this->red_curve->curveto(this->p[1], this->p[2], this->p[3]);
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve, true);
}
SP_CTRL(this->c0)->moveto(this->p[2]);
this->cl0 ->setCoords(this->p[3], this->p[2]);
@@ -1856,13 +1844,13 @@ void PenTool::_finishSegment(Geom::Point const p, guint const state) {
++num_clicks;
- if (!this->red_curve->is_empty()) {
+ if (!this->red_curve->is_unset()) {
this->_bsplineSpiro(state & GDK_SHIFT_MASK);
this->green_curve->append_continuous(this->red_curve, 0.0625);
SPCurve *curve = this->red_curve->copy();
/// \todo fixme:
- SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), curve);
+ SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), curve, true);
curve->unref();
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvas_shape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
@@ -1881,8 +1869,8 @@ void PenTool::_finishSegment(Geom::Point const p, guint const state) {
bool PenTool::_undoLastPoint() {
bool ret = false;
- if ( this->green_curve->is_empty() || (this->green_curve->last_segment() == NULL) ) {
- if (!this->red_curve->is_empty()) {
+ if ( this->green_curve->is_unset() || (this->green_curve->last_segment() == NULL) ) {
+ if (!this->red_curve->is_unset()) {
this->_cancel ();
ret = true;
} else {
@@ -1899,7 +1887,7 @@ bool PenTool::_undoLastPoint() {
this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data);
}
// Get last segment
- if ( this->green_curve->is_empty() ) {
+ if ( this->green_curve->is_unset() ) {
g_warning("pen_handle_key_press, case GDK_KP_Delete: Green curve is empty");
return false;
}
@@ -2031,7 +2019,7 @@ int PenTool::nextParaxialDirection(Geom::Point const &pt, Geom::Point const &ori
// (on first mouse release), in which case num_clicks immediately becomes 1.
// if (this->num_clicks == 0) {
- if (this->green_curve->is_empty()) {
+ if (this->green_curve->is_unset()) {
// first mouse click
double dist_h = fabs(pt[Geom::X] - origin[Geom::X]);
double dist_v = fabs(pt[Geom::Y] - origin[Geom::Y]);