pen-tool.cpp revision e49a8d598760223e8cf5ed08267b555b793079e6
/** \file
* Pen event context implementation.
*/
/*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2000 Lauris Kaplinski
* Copyright (C) 2000-2001 Ximian, Inc.
* Copyright (C) 2002 Lauris Kaplinski
* Copyright (C) 2004 Monash University
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <gdk/gdkkeysyms.h>
#include <cstring>
#include <string>
#include "ui/tools/pen-tool.h"
#include "sp-namedview.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "selection.h"
#include "selection-chemistry.h"
#include "draw-anchor.h"
#include "message-stack.h"
#include "message-context.h"
#include "preferences.h"
#include "sp-path.h"
#include "display/sp-canvas.h"
#include "pixmaps/cursor-pen.xpm"
#include "display/canvas-bpath.h"
#include "display/sp-ctrlline.h"
#include "display/sodipodi-ctrl.h"
#include "macros.h"
#include "context-fns.h"
#include "tools-switch.h"
#include "ui/control-manager.h"
//spanish: incluimos los archivos necesarios para las BSpline y Spiro
#include "live_effects/effect.h"
#include "live_effects/lpeobject.h"
#include "live_effects/lpeobject-reference.h"
#include "live_effects/parameter/path.h"
#define INKSCAPE_LPE_SPIRO_C
#include "live_effects/lpe-spiro.h"
#include <typeinfo>
#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 "tool-factory.h"
#include "live_effects/effect.h"
using Inkscape::ControlManager;
namespace Inkscape {
namespace UI {
namespace Tools {
static bool pen_within_tolerance = false;
static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical
namespace {
ToolBase* createPenContext() {
return new PenTool();
}
bool penContextRegistered = ToolFactory::instance().registerObject("/tools/freehand/pen", createPenContext);
}
}
, p()
, npoints(0)
, mode(MODE_CLICK)
, polylines_only(false)
, polylines_paraxial(false)
, num_clicks(0)
, waiting_LPE(NULL)
, waiting_item(NULL)
, events_disabled(false)
{
}
, p()
, npoints(0)
, mode(MODE_CLICK)
, polylines_only(false)
, polylines_paraxial(false)
, num_clicks(0)
, waiting_LPE(NULL)
, waiting_item(NULL)
, events_disabled(false)
{
}
if (this->c0) {
sp_canvas_item_destroy(this->c0);
}
if (this->c1) {
sp_canvas_item_destroy(this->c1);
}
if (this->cl0) {
sp_canvas_item_destroy(this->cl0);
}
if (this->cl1) {
sp_canvas_item_destroy(this->cl1);
}
if (this->expecting_clicks_for_LPE > 0) {
// we received too few clicks to sanely set the parameter path so we remove the LPE from the item
this->waiting_item->removeCurrentPathEffect(false);
}
}
void PenTool::setPolylineMode() {
//spanish: cambiamos los modos para dar cabida al modo bspline
//we call the function which defines the Spiro modes and the BSpline
//todo: merge to one function only
this->_pen_context_set_mode(mode);
}
/*
*.Set the mode of draw spiro, and bsplines
*/
//spanish: definimos los modos
}
/**
* Callback to initialize PenTool object.
*/
FreehandBase::setup();
// Pen indicators
sp_canvas_item_hide(this->c0);
sp_canvas_item_hide(this->c1);
sp_canvas_item_hide(this->cl0);
sp_canvas_item_hide(this->cl1);
sp_event_context_read(this, "mode");
this->anchor_statusbar = false;
this->setPolylineMode();
this->enableSelectionCue();
}
}
this->num_clicks = 0;
this->_resetColors();
sp_canvas_item_hide(this->c0);
sp_canvas_item_hide(this->c1);
sp_canvas_item_hide(this->cl0);
sp_canvas_item_hide(this->cl1);
this->message_context->clear();
}
/**
* Finalization callback.
*/
if (this->npoints != 0) {
this->_cancel();
}
FreehandBase::finish();
}
/**
* Callback that sets key to value in pen context.
*/
if (name == "mode") {
} else {
this->mode = MODE_CLICK;
}
}
}
bool PenTool::hasWaitingLPE() {
// note: waiting_LPE_type is defined in SPDrawContext
return (this->waiting_LPE != NULL ||
}
/**
* Snaps new node relative to the previous node.
*/
if (this->npoints > 0) {
spdc_endpoint_snap_rotation(this, p, this->p[0], state);
}
} else {
// We cannot use shift here to disable snapping because the shift-key is already used
// to toggle the paraxial direction; if the user wants to disable snapping (s)he will
// have to use the %-key, the menu, or the snap toolbar
if ((this->npoints > 0) && this->polylines_paraxial) {
// snap constrained
this->_setToNearestHorizVert(p, state, true);
} else {
// snap freely
boost::optional<Geom::Point> origin = this->npoints > 0 ? this->p[0] : boost::optional<Geom::Point>();
spdc_endpoint_snap_free(this, p, origin, state); // pass the origin, to allow for perpendicular / tangential snapping
}
}
}
/**
* Snaps new node's handle relative to the new node.
*/
this->npoints == 5 ));
} else {
}
}
}
case GDK_BUTTON_PRESS:
break;
case GDK_BUTTON_RELEASE:
break;
default:
break;
}
if (!ret) {
}
return ret;
}
/**
* Callback to handle all pen events.
*/
case GDK_BUTTON_PRESS:
break;
case GDK_MOTION_NOTIFY:
break;
case GDK_BUTTON_RELEASE:
break;
case GDK_2BUTTON_PRESS:
break;
case GDK_KEY_PRESS:
break;
default:
break;
}
if (!ret) {
}
return ret;
}
/**
* Handle mouse button press event.
*/
if (this->events_disabled) {
// skip event processing if events are disabled
return FALSE;
}
//Test whether we hit any anchor.
//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]){
//spanish Borrar siguiente linea para evitar un nodo encima de otro
return TRUE;
}
return FALSE;
}
// make sure this is not the last click for a waiting LPE (otherwise we want to finish the path)
&& this->expecting_clicks_for_LPE != 1) {
return TRUE;
}
if (!this->grab ) {
// Grab mouse, so release will not pass unnoticed
}
pen_within_tolerance = true;
switch (this->mode) {
case PenTool::MODE_CLICK:
// In click mode we add point on release
switch (this->state) {
break;
// This is allowed, if we just canceled curve
break;
default:
break;
}
break;
switch (this->state) {
// This is allowed, if we just canceled curve
if (this->npoints == 0) {
p = event_dt;
m.unSetup();
}
break;
}
// TODO: Perhaps it would be nicer to rearrange the following case
// distinction so that the case of a waiting LPE is treated separately
// Set start anchor
if(anchor){
}
// Adjust point to anchor if needed; if we have a waiting LPE, we need
// a fresh path to be created so don't continue an existing one
} else {
// This is the first click of a new curve; deselect item so that
// this curve is not combined with it (unless it is drawn from its
// anchor, which is handled by the sibling branch above)
// if we have a waiting LPE, we need a fresh path to be created
// so don't append to an existing one
}
// Create green anchor
p = event_dt;
}
this->_setInitialPoint(p);
} else {
// Set end anchor
if (anchor) {
// we hit an anchor, will finish the curve (either with or without closing)
// in release handler
// we clicked on the current curve start, so close it even if
// we drag a handle away from it
}
break;
} else {
p = event_dt;
this->_setSubsequentPoint(p, true);
}
}
//spanish: evitamos la creación de un punto de control para que se cree el nodo en el evento de soltar
this->state = (this->spiro || this->bspline || this->polylines_only) ? PenTool::POINT : PenTool::CONTROL;
break;
g_warning("Button down in CONTROL state");
break;
g_warning("Button down in CLOSE state");
break;
default:
break;
}
break;
default:
break;
}
// when the last click for a waiting LPE occurs we want to finish the path
if (this->green_closed) {
// finishing at the start anchor, close curve
} else {
// finishing at some other anchor, finish curve but not close
}
// right click - finish path
}
if (this->expecting_clicks_for_LPE > 0) {
--this->expecting_clicks_for_LPE;
}
return ret;
}
/**
* Handle motion_notify event.
*/
if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) {
// allow scrolling
return FALSE;
}
if (this->events_disabled) {
// skip motion events if pen events are disabled
return FALSE;
}
mevent.y);
//we take out the function the const "tolerance" because we need it later
if (pen_within_tolerance) {
return FALSE; // Do not drag if we're within tolerance from origin.
}
}
// Once the user has moved farther than tolerance from the original location
// (indicating they intend to move the object, not click), then always process the
// motion notify coordinates as given (no snapping back to origin)
pen_within_tolerance = false;
// Find desktop coordinates
// Test, whether we hit any anchor
switch (this->mode) {
case PenTool::MODE_CLICK:
switch (this->state) {
if ( this->npoints != 0 ) {
// Only set point, if we are already appending
this->_setSubsequentPoint(p, true);
} else if (!this->sp_event_context_knot_mouseover()) {
m.unSetup();
}
break;
// Placing controls is last operation in CLOSE state
break;
// This is perfectly valid
break;
default:
break;
}
break;
switch (this->state) {
if ( this->npoints > 0 ) {
// Only set point, if we are already appending
if (!anchor) { // Snap node only if not hitting anchor
} else {
}
if (anchor && !this->anchor_statusbar) {
this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path."));
}else{
this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path. Shift to cusp node"));
}
this->anchor_statusbar = true;
} else if (!anchor && this->anchor_statusbar) {
this->message_context->clear();
this->anchor_statusbar = false;
}
} else {
if (anchor && !this->anchor_statusbar) {
this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point."));
}else{
this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point. Shift to cusp node"));
}
this->anchor_statusbar = true;
} else if (!anchor && this->anchor_statusbar) {
this->message_context->clear();
this->anchor_statusbar = false;
}
if (!this->sp_event_context_knot_mouseover()) {
m.unSetup();
}
}
break;
// Placing controls is last operation in CLOSE state
// snap the handle
if (!this->polylines_only) {
} else {
}
break;
// This is perfectly valid
break;
default:
if (!this->sp_event_context_knot_mouseover()) {
m.unSetup();
}
break;
}
break;
default:
break;
}
//spanish: lanzamos la función "bspline_spiro_motion" al moverse el ratón o cuando se para.
if(this->bspline){
this->_bspline_spiro_color();
}else{
this->_bspline_spiro_color();
}
}
return ret;
}
/**
* Handle mouse button release event.
*/
if (this->events_disabled) {
// skip event processing if events are disabled
return FALSE;
}
revent.y);
// Find desktop coordinates
// Test whether we hit any anchor.
//with this we avoid creating a new point over the existing one
//spanish: si intentamos crear un nodo en el mismo sitio que el origen, paramos.
if((!anchor || anchor == this->sa) && (this->spiro || this->bspline) && this->npoints > 0 && this->p[0] == this->p[3]){
return TRUE;
}
switch (this->mode) {
case PenTool::MODE_CLICK:
switch (this->state) {
if ( this->npoints == 0 ) {
// Start new thread only with button release
if (anchor) {
}
//spanish: continuamos una curva existente
if (anchor) {
}
}
this->_setInitialPoint(p);
} else {
// Set end anchor here
if (anchor) {
}
}
break;
// End current segment
break;
// End current segment
if (!anchor) { // Snap node only if not hitting anchor
}
//spanish: ocultamos la guia del penultimo nodo al cerrar la curva
if(this->spiro){
sp_canvas_item_hide(this->c1);
}
break;
// This is allowed, if we just canceled curve
break;
default:
break;
}
break;
switch (this->state) {
break;
//spanish: ocultamos la guia del penultimo nodo al cerrar la curva
if(this->spiro){
sp_canvas_item_hide(this->c1);
}
if (this->green_closed) {
// finishing at the start anchor, close curve
} else {
// finishing at some other anchor, finish curve but not close
}
break;
// This is allowed, if we just cancelled curve
break;
default:
break;
}
break;
default:
break;
}
if (this->grab) {
// Release grab now
}
}
// TODO: can we be sure that the path was created correctly?
// TODO: should we offer an option to collect the clicks in a list?
if (this->expecting_clicks_for_LPE == 0 && this->hasWaitingLPE()) {
this->setPolylineMode();
if (this->waiting_LPE) {
// we have an already created LPE waiting for a path
this->waiting_LPE = NULL;
} else {
// the case that we need to create a new LPE and apply it to the just-drawn path is
// handled in spdc_check_for_and_apply_waiting_LPE() in draw-context.cpp
}
}
return ret;
}
// only end on LMB double click. Otherwise horizontal scrolling causes ending of the path
}
return ret;
}
void PenTool::_redrawAll() {
// green
if (this->green_bpaths) {
// remove old piecewise green canvasitems
while (this->green_bpaths) {
}
// one canvas bpath for all of green_curve
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
}
if (this->green_anchor)
// handles
//spanish: ocultamos los tiradores en modo bspline y spiro
sp_canvas_item_show(this->c1);
sp_canvas_item_show(this->cl1);
} else {
sp_canvas_item_hide(this->c1);
sp_canvas_item_hide(this->cl1);
}
if (last_seg) {
//spanish: ocultamos los tiradores en modo bspline y spiro
if ( cubic &&
{
sp_canvas_item_show(this->c0);
sp_canvas_item_show(this->cl0);
} else {
sp_canvas_item_hide(this->c0);
sp_canvas_item_hide(this->cl0);
}
}
//spanish: simplemente redibujamos la spiro.
//como es un redibujo simplemente no llamamos a la función global sino al final de esta
//Lanzamos solamente el redibujado
this->_bspline_spiro_build();
}
if (this->npoints != 5)
return;
// green
if (!this->green_curve->is_empty()) {
} else {
// start anchor too
if (this->green_anchor) {
}
}
// red
this->_redrawAll();
}
}
void PenTool::_lastpointToCurve() {
//spanish: evitamos que si la "red_curve" tiene solo dos puntos -recta- no se pare aqui.
return;
this->p[1] = this->red_curve->last_segment()->initialPoint() + (1./3)* (Geom::Point)(this->red_curve->last_segment()->finalPoint() - this->red_curve->last_segment()->initialPoint());
//spanish: modificamos el último segmento de la curva verde para que forme el tipo de nodo que deseamos
if(!this->green_curve->is_empty()){
//We obtain the last segment 4 points in the previous curve
if ( cubic ){
A = (*cubic)[0];
B = (*cubic)[1];
if(this->spiro){
}else
C = this->green_curve->last_segment()->finalPoint() + (1./3)* (Geom::Point)(this->green_curve->last_segment()->initialPoint() - this->green_curve->last_segment()->finalPoint());
D = (*cubic)[3];
}else{
if(this->spiro)
else
C = this->green_curve->last_segment()->finalPoint() + (1./3)* (Geom::Point)(this->green_curve->last_segment()->initialPoint() - this->green_curve->last_segment()->finalPoint());
}
this->green_curve = previous;
}else{
//we eliminate the last segment
this->green_curve->backspace();
//and we add it again with the recreation
}
}
//spanish: si el último nodo es una union con otra curva
this->_bspline_spiro_start_anchor(false);
}
}
this->_redrawAll();
}
void PenTool::_lastpointToLine() {
//spanish: evitamos que si la "red_curve" tiene solo dos puntos -recta- no se pare aqui.
return;
//spanish: modificamos el último segmento de la curva verde para que forme el tipo de nodo que deseamos
if(!this->green_curve->is_empty()){
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( this->green_curve->last_segment() );
if ( cubic ) {
B = (*cubic)[1];
D = C;
} else {
//We obtain the last segment 4 points in the previous curve
B = A;
D = C;
}
this->green_curve = previous;
}else{
//we eliminate the last segment
this->green_curve->backspace();
//and we add it again with the recreation
}
}
//spanish: si el último nodo es una union con otra curva
this->_bspline_spiro_start_anchor(true);
}
}
this->p[1] = this->p[0];
this->_redrawAll();
}
gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px
case GDK_KEY_Left: // move last point left
case GDK_KEY_KP_Left:
}
else { // no alt
}
}
break;
case GDK_KEY_Up: // move last point up
case GDK_KEY_KP_Up:
}
else { // no alt
}
}
break;
case GDK_KEY_Right: // move last point right
case GDK_KEY_KP_Right:
}
else { // no alt
}
}
break;
case GDK_KEY_Down: // move last point down
case GDK_KEY_KP_Down:
}
else { // no alt
}
}
break;
/*TODO: this is not yet enabled?? looks like some traces of the Geometry tool
case GDK_KEY_P:
case GDK_KEY_p:
if (MOD__SHIFT_ONLY(event)) {
sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PARALLEL, 2);
ret = TRUE;
}
break;
case GDK_KEY_C:
case GDK_KEY_c:
if (MOD__SHIFT_ONLY(event)) {
sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::CIRCLE_3PTS, 3);
ret = TRUE;
}
break;
case GDK_KEY_B:
case GDK_KEY_b:
if (MOD__SHIFT_ONLY(event)) {
sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PERP_BISECTOR, 2);
ret = TRUE;
}
break;
case GDK_KEY_A:
case GDK_KEY_a:
if (MOD__SHIFT_ONLY(event)) {
sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::ANGLE_BISECTOR, 3);
ret = TRUE;
}
break;
*/
case GDK_KEY_U:
case GDK_KEY_u:
if (MOD__SHIFT_ONLY(event)) {
this->_lastpointToCurve();
}
break;
case GDK_KEY_L:
case GDK_KEY_l:
if (MOD__SHIFT_ONLY(event)) {
this->_lastpointToLine();
}
break;
case GDK_KEY_Return:
case GDK_KEY_KP_Enter:
if (this->npoints != 0) {
}
break;
case GDK_KEY_Escape:
if (this->npoints != 0) {
// if drawing, cancel, otherwise pass it up for deselecting
this->_cancel ();
}
break;
case GDK_KEY_z:
case GDK_KEY_Z:
// if drawing, cancel, otherwise pass it up for undo
this->_cancel ();
}
break;
case GDK_KEY_g:
case GDK_KEY_G:
if (MOD__SHIFT_ONLY(event)) {
ret = true;
}
break;
case GDK_KEY_BackSpace:
case GDK_KEY_Delete:
case GDK_KEY_KP_Delete:
this->_cancel ();
} else {
// do nothing; this event should be handled upstream
}
} else {
// Reset red curve
// Destroy topmost green bpath
if (this->green_bpaths) {
if (this->green_bpaths->data)
}
// Get last segment
if ( this->green_curve->is_empty() ) {
g_warning("pen_handle_key_press, case GDK_KP_Delete: Green curve is empty");
break;
}
// The code below assumes that this->green_curve has only ONE path !
this->p[0] = crv->initialPoint();
} else {
this->p[1] = this->p[0];
}
//spanish: asignamos el valor a un tercio de distancia del último segmento.
if(this->bspline){
this->p[1] = this->p[0] + (1./3)*(this->p[3] - this->p[0]);
}
: this->p[3]));
this->npoints = 2;
//spanish: eliminamos el último segmento de la curva verde
this->npoints = 5;
if (this->green_bpaths) {
if (this->green_bpaths->data)
}
this->green_curve->reset();
}else{
this->green_curve->backspace();
}
//spanish: asignamos el valor de this->p[1] a el opuesto de el ultimo segmento de la lÃnea verde
if(this->spiro){
if ( cubic ) {
} else {
this->p[1] = this->p[0];
}
}
sp_canvas_item_hide(this->cl0);
sp_canvas_item_hide(this->cl1);
this->_setSubsequentPoint(pt, true);
//spanish: redibujamos
this->_bspline_spiro_build();
}
break;
default:
break;
}
return ret;
}
void PenTool::_resetColors() {
// Red
// Blue
this->blue_curve->reset();
// Blue2
this->blue2_curve->reset();
// Green
while (this->green_bpaths) {
}
this->green_curve->reset();
if (this->green_anchor) {
}
this->npoints = 0;
this->red_curve_is_valid = false;
}
this->p[0] = p;
this->p[1] = p;
this->npoints = 2;
}
/**
* two parameters ("angle %3.2f°, distance %s").
*/
void PenTool::_setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_to_compare, gchar const *message) {
if (angle < 0) {
angle += 360;
}
}
}
//spanish: esta función cambia los colores rojo,verde y azul haciendolos transparentes o no en función de si se usa spiro
void PenTool::_bspline_spiro_color()
{
bool remake_green_bpaths = false;
if(this->spiro){
//If the colour is not defined as trasparent, por example when changing
//from drawing to spiro mode or when selecting the pen tool
if(this->green_color != 0x00ff000){
//We change the green and red colours to transparent, so this lines are not necessary
//to the drawing with spiro
this->red_color = 0xff00000;
this->green_color = 0x00ff000;
remake_green_bpaths = true;
}
}else if(this->bspline){
//If we come from working with the spiro curve and change the mode the "green_curve" colour is transparent
if(this->green_color != 0xff00007f){
//since we are not im spiro mode, we assign the original colours
//to the red and the green curve, removing their transparency
this->red_color = 0xff00007f;
//Damos color rojo a la linea verde
this->green_color = 0xff00007f;
remake_green_bpaths = true;
}
}else{
//If we come from working with the spiro curve and change the mode the "green_curve" colour is transparent
if(this->green_color != 0x00ff007f){
//since we are not im spiro mode, we assign the original colours
//to the red and the green curve, removing their transparency
this->red_color = 0xff00007f;
this->green_color = 0x00ff007f;
remake_green_bpaths = true;
}
sp_canvas_item_hide(this->blue2_bpath);
}
//We erase all the "green_bpaths" to recreate them after with the colour
//transparency recently modified
if (this->green_bpaths && remake_green_bpaths) {
// remove old piecewise green canvasitems
while (this->green_bpaths) {
}
// one canvas bpath for all of green_curve
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
}
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->red_bpath), this->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
}
{
return;
this->_bspline_spiro_build();
}
void PenTool::_bspline_spiro_on()
{
using Geom::X;
using Geom::Y;
this->npoints = 5;
this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]);
}
}
void PenTool::_bspline_spiro_off()
{
this->npoints = 5;
this->p[2] = this->p[3];
}
}
{
Inkscape::LivePathEffect::Effect* thisEffect = SP_LPE_ITEM(this->white_item)->getPathEffectOfType(Inkscape::LivePathEffect::BSPLINE);
if(thisEffect){
}
}
if(lpe_bsp){
this->bspline = true;
}else{
this->bspline = false;
}
Inkscape::LivePathEffect::Effect* thisEffect = SP_LPE_ITEM(this->white_item)->getPathEffectOfType(Inkscape::LivePathEffect::SPIRO);
if(thisEffect){
}
}
if(lpe_spi){
this->spiro = true;
}else{
this->spiro = false;
}
return;
return;
if(shift)
this->_bspline_spiro_start_anchor_off();
else
this->_bspline_spiro_start_anchor_on();
}
{
using Geom::X;
using Geom::Y;
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
if(cubic){
}else{
}
}else{
//we eliminate the last segment
//and we add it again with the recreation
}
}
}
{
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
if(cubic){
}else{
//we eliminate the last segment
//and we add it again with the recreation
}
}
}
}
return;
using Geom::X;
using Geom::Y;
this->npoints = 5;
this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]);
this->p[1] = this->p[0] + (1./3)*(this->p[3] - this->p[0]);
}else if(!this->green_curve->is_empty()){
}else{
}
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
if(cubic){
if(this->bspline){
if(shift)
this->p[2] = this->p[3];
}else{
}
}else{
this->p[1] = this->p[0];
if(shift)
this->p[2] = this->p[3];
}
}
if(shift){
this->_bspline_spiro_end_anchor_off();
}else{
this->_bspline_spiro_end_anchor_on();
}
}
this->_bspline_spiro_build();
}
void PenTool::_bspline_spiro_end_anchor_on()
{
using Geom::X;
using Geom::Y;
this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]);
if(this->green_curve->get_segment_count()==0)return;
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
if(this->bspline){
C = tmpCurve->last_segment()->finalPoint() + (1./3)*(tmpCurve->last_segment()->initialPoint() - tmpCurve->last_segment()->finalPoint());
}else{
}
if(cubic){
}else{
lastSeg->curveto(tmpCurve->last_segment()->initialPoint(),C,tmpCurve->last_segment()->finalPoint());
}
}else{
//we eliminate the last segment
//and we add it again with the recreation
}
this->green_curve->reset();
this->green_curve = tmpCurve;
}else {
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
if(this->bspline){
C = tmpCurve->last_segment()->finalPoint() + (1./3)*(tmpCurve->last_segment()->initialPoint() - tmpCurve->last_segment()->finalPoint());
}else{
}
if(cubic){
}else{
lastSeg->curveto(tmpCurve->last_segment()->initialPoint(),C,tmpCurve->last_segment()->finalPoint());
}
}else{
//we eliminate the last segment
//and we add it again with the recreation
}
}
}
}
void PenTool::_bspline_spiro_end_anchor_off()
{
this->p[2] = this->p[3];
if(this->green_curve->get_segment_count()==0)return;
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
if(cubic){
}else{
//we eliminate the last segment
//and we add it again with the recreation
}
this->green_curve->reset();
this->green_curve = tmpCurve;
}
}else {
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
if(cubic){
}else{
//we eliminate the last segment
//and we add it again with the recreation
}
}
}
}
}
//spanish: preparates the curves for its trasformation into BSline curves.
void PenTool::_bspline_spiro_build()
{
return;
//We create the base curve
//If we continuate the existing curve we add it at the start
}
}
if (!this->green_curve->is_empty())
//and the red one
}
//spanish: cerramos la curva si estan cerca los puntos finales de la curva
}
//TODO: CALL TO CLONED FUNCTION SPIRO::doEffect IN lpe-spiro.cpp
//For example
//using namespace Inkscape::LivePathEffect;
//LivePathEffectObject *lpeobj = static_cast<LivePathEffectObject*> (curve);
//Effect *spr = static_cast<Effect*> ( new LPEbspline(lpeobj) );
//spr->doEffect(curve);
if(this->bspline){
this->_bspline_doEffect(curve);
}else{
this->_spiro_doEffect(curve);
}
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->blue2_bpath), this->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_item_show(this->blue2_bpath);
this->blue2_curve->reset();
//We hide the holders that doesn't contribute anything
if(this->spiro){
sp_canvas_item_show(this->c1);
}else
sp_canvas_item_hide(this->c1);
sp_canvas_item_hide(this->cl1);
sp_canvas_item_hide(this->c0);
sp_canvas_item_hide(this->cl0);
}else{
//if the curve is empty
sp_canvas_item_hide(this->blue2_bpath);
}
}
{
//spanish: comentado en funcion "doEffect" de src/live_effects/lpe-bspline.cpp
return;
for(Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) {
continue;
Geom::Path::const_iterator curve_endit = path_it->end_default(); // this determines when the loop has to stop
const Geom::Curve &closingline = path_it->back_closed(); // the closing line segment is always of type Geom::LineSegment.
}
}
while ( curve_it2 != curve_endit )
{
if(cubic){
}else{
}
delete in;
if(cubic){
}else{
}
delete out;
lineHelper->reset();
delete lineHelper;
previousNode = node;
curveHelper->reset();
delete curveHelper;
++curve_it1;
++curve_it2;
}
if(cubic){
}else{
}
delete start;
if(cubic){
}else{
}
delete end;
lineHelper->reset();
delete lineHelper;
}else{
delete start;
}
curveHelper->reset();
delete curveHelper;
}
delete nCurve;
}
}
//Spiro function cloned from lpe-spiro.cpp
//spanish: comentado en funcion "doEffect" de src/live_effects/lpe-spiro.cpp
{
using Geom::X;
using Geom::Y;
int ip = 0;
for(Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) {
continue;
{
ip++;
}
}
}
while ( curve_it2 != curve_endit )
{
{
if (this_is_line && !next_is_line) {
} else if (next_is_line && !this_is_line) {
} else {
}
} else {
}
++curve_it1;
++curve_it2;
ip++;
}
switch (nodetype) {
ip++;
break;
break;
case Geom::NODE_SMOOTH:
break;
}
} else {
ip++;
}
ip = 0;
}
}
// todo: Check callers to see whether 2 <= npoints is guaranteed.
this->p[2] = p;
this->p[3] = p;
this->p[4] = p;
this->npoints = 5;
bool is_curve;
if (this->polylines_paraxial && !statusbar) {
// we are drawing horizontal/vertical lines and hit an anchor;
// if the previous point and the anchor are not aligned either horizontally or vertically...
// ...then we should draw an L-shaped path, consisting of two paraxial segments
}
is_curve = false;
} else {
// one of the 'regular' modes
if (this->p[1] != this->p[0] || this->spiro) {
is_curve = true;
} else {
is_curve = false;
}
}
if (statusbar) {
_("<b>Curve segment</b>: angle %3.2f°, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path" ):
_("<b>Line segment</b>: angle %3.2f°, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path");
_("<b>Curve segment</b>: angle %3.2f°, distance %s; with <b>Shift</b> to cusp node, <b>Enter</b> to finish the path" ):
_("<b>Line segment</b>: angle %3.2f°, distance %s; with <b>Shift</b> to cusp node, <b>Enter</b> to finish the path");
}
this->_setAngleDistanceStatusMessage(p, 0, message);
}
}
sp_canvas_item_show(this->c1);
sp_canvas_item_show(this->cl1);
if ( this->npoints == 2 ) {
this->p[1] = p;
sp_canvas_item_hide(this->c0);
sp_canvas_item_hide(this->cl0);
this->_setAngleDistanceStatusMessage(p, 0, _("<b>Curve handle</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle"));
} else if ( this->npoints == 5 ) {
this->p[4] = p;
sp_canvas_item_show(this->c0);
sp_canvas_item_show(this->cl0);
bool is_symm = false;
is_symm = true;
}
_("<b>Curve handle, symmetric</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle, with <b>Shift</b> to move this handle only") :
_("<b>Curve handle</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle, with <b>Shift</b> to move this handle only");
} else {
}
}
if (this->polylines_paraxial) {
}
++this->num_clicks;
/// \todo fixme:
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
this->p[0] = this->p[3];
this->p[1] = this->p[4];
this->npoints = 2;
}
}
if (this->expecting_clicks_for_LPE > 1) {
// don't let the path be finished before we have collected the required number of mouse clicks
return;
}
this->num_clicks = 0;
this->_disableEvents();
this->message_context->clear();
//spanish para cancelar linea sin un segmento creado
spdc_concat_colors_and_flush(this, closed);
this->npoints = 0;
sp_canvas_item_hide(this->c0);
sp_canvas_item_hide(this->c1);
sp_canvas_item_hide(this->cl0);
sp_canvas_item_hide(this->cl1);
if (this->green_anchor) {
}
this->_enableEvents();
}
void PenTool::_disableEvents() {
this->events_disabled = true;
}
void PenTool::_enableEvents() {
g_return_if_fail(this->events_disabled != 0);
this->events_disabled = false;
}
void PenTool::waitForLPEMouseClicks(Inkscape::LivePathEffect::EffectType effect_type, unsigned int num_clicks, bool use_polylines) {
return;
this->waiting_LPE_type = effect_type;
this->expecting_clicks_for_LPE = num_clicks;
this->polylines_only = use_polylines;
this->polylines_paraxial = false; // TODO: think if this is correct for all cases
}
int PenTool::nextParaxialDirection(Geom::Point const &pt, Geom::Point const &origin, guint state) const {
//
// after the first mouse click we determine whether the mouse pointer is closest to a
// horizontal or vertical segment; for all subsequent mouse clicks, we use the direction
// orthogonal to the last one; pressing Shift toggles the direction
//
// num_clicks is not reliable because spdc_pen_finish_segment is sometimes called too early
// (on first mouse release), in which case num_clicks immediately becomes 1.
// if (this->num_clicks == 0) {
if (this->green_curve->is_empty()) {
// first mouse click
return pen_last_paraxial_dir;
} else {
// subsequent mouse click
}
}
if (!snap) {
if (next_dir == 0) {
// line is forced to be horizontal
} else {
// line is forced to be vertical
}
} else {
// Create a horizontal or vertical constraint line
// Snap along the constraint line; if we didn't snap then still the constraint will be applied
// selection->singleItem() is the item that is currently being drawn. This item will not be snapped to (to avoid self-snapping)
// TODO: Allow snapping to the stationary parts of the item, and only ignore the last segment
m.unSetup();
}
}
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :