pen-tool.cpp revision 2bb69788f9098cbff5f2e91dde4a11cae938cc0c
/** \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"
//BSpline
//Incluimos los archivos necesarios para las BSpline y Spiro
#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"
//BSpline End
#include "tool-factory.h"
using Inkscape::ControlManager;
namespace Inkscape {
namespace UI {
namespace Tools {
/*
*BSpline
*Added functions
*/
//Añade los modos spiro y bspline
//Esta función cambia los colores rojo,verde y azul haciendolos transparentes o no en función de si se usa spiro
//Crea un nodo en modo bspline o spiro
//Crea un nodo de modo spiro o bspline
//Crea un nodo de tipo CUSP
//Continua una curva existente en modo bspline o spiro
//Continua una curva exsitente con el nodo de union en modo bspline o spiro
//Continua una curva existente con el nodo de union en modo CUSP
//Modifica la "red_curve" cuando se detecta movimiento
//Cierra la curva con el último nodo en modo bspline o spiro
//Cierra la curva con el último nodo en modo CUSP
//Unimos todas las curvas en juego y llamamos a la función doEffect.
//function bspline cloned from lpe-bspline.cpp
//function spiro cloned from lpe-spiro.cpp
//BSpline end
static void spdc_pen_set_subsequent_point(PenTool *const pc, Geom::Point const p, bool statusbar, guint status = 0);
static bool pen_within_tolerance = false;
static int pen_next_paraxial_direction(const PenTool *const pc, Geom::Point const &pt, Geom::Point const &origin, guint state);
static void pen_set_to_nearest_horiz_vert(const PenTool *const pc, Geom::Point &pt, guint const state, bool snap);
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);
}
}
this->polylines_only = false;
this->polylines_paraxial = false;
this->expecting_clicks_for_LPE = 0;
this->cursor_shape = cursor_pen_xpm;
this->hot_x = 4;
this->hot_y = 4;
this->npoints = 0;
this->mode = MODE_CLICK;
this->events_disabled = 0;
this->num_clicks = 0;
this->waiting_LPE = NULL;
this->waiting_item = NULL;
}
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);
}
}
//BSpline
//we call the function which defines the Spiro modes and the BSpline
//todo: merge to one function only
//BSpline End
}
//BSpline
/*
*.Set the mode of draw spiro, and bsplines
*/
}
//BSpline End
/**
* 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->enableSelectionCue();
}
}
{
pc->num_clicks = 0;
}
/**
* Finalization callback.
*/
if (this->npoints != 0) {
pen_cancel(this);
}
FreehandBase::finish();
}
/**
* Callback that sets key to value in pen context.
*/
if (name == "mode") {
} else {
this->mode = MODE_CLICK;
}
}
}
/**
* Snaps new node relative to the previous node.
*/
{
}
} 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
// snap constrained
} else {
// snap freely
spdc_endpoint_snap_free(pc, p, origin, state); // pass the origin, to allow for perpendicular / tangential snapping
}
}
}
/**
* Snaps new node's handle relative to the new node.
*/
{
} 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 (pc->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
return FALSE;
}
//BSpline end
// make sure this is not the last click for a waiting LPE (otherwise we want to finish the path)
return TRUE;
}
// Grab mouse, so release will not pass unnoticed
}
pen_within_tolerance = true;
case PenTool::MODE_CLICK:
// In click mode we add point on release
break;
// This is allowed, if we just canceled curve
break;
default:
break;
}
break;
// This is allowed, if we just canceled curve
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
//BSpline
//Continuamos una curva existente
if(anchor){
}
//BSpline End
// 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;
}
} 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;
spdc_pen_set_subsequent_point(pc, p, true);
}
}
//BSpline
//Evitamos la creación de un punto de control para que se cree el nodo en el evento de soltar
//BSpline End
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 (pc->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 (pc->expecting_clicks_for_LPE > 0) {
}
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 (pc->events_disabled) {
// skip motion events if pen events are disabled
return FALSE;
}
mevent.y);
//BSpline
//we take out the function the const "tolerance" because we need it later
//"spiro_color" lo ejecutamos siempre sea o no spiro
if (pen_within_tolerance) {
return FALSE; // Do not drag if we're within tolerance from origin.
}
}
//BSpline END
// 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
case PenTool::MODE_CLICK:
// Only set point, if we are already appending
spdc_pen_set_subsequent_point(pc, p, true);
} else if (!sp_event_context_knot_mouseover(pc)) {
m.unSetup();
}
break;
// Placing controls is last operation in CLOSE state
break;
// This is perfectly valid
break;
default:
break;
}
break;
// Only set point, if we are already appending
if (!anchor) { // Snap node only if not hitting anchor
} else {
}
pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path."));
}else{
pc->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"));
}
pc->anchor_statusbar = true;
pc->anchor_statusbar = false;
}
} else {
pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point."));
}else{
pc->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"));
}
pc->anchor_statusbar = true;
pc->anchor_statusbar = false;
}
if (!sp_event_context_knot_mouseover(pc)) {
m.unSetup();
}
}
break;
// Placing controls is last operation in CLOSE state
// snap the handle
if (!pc->polylines_only) {
} else {
}
break;
// This is perfectly valid
break;
default:
if (!sp_event_context_knot_mouseover(pc)) {
m.unSetup();
}
break;
}
break;
default:
break;
}
//BSpline
//Lanzamos la función "bspline_spiro_motion" al moverse el ratón o cuando se para.
}else{
}
}
//BSpline End
return ret;
}
/**
* Handle mouse button release event.
*/
{
if (pc->events_disabled) {
// skip event processing if events are disabled
return FALSE;
}
revent.y);
// Find desktop coordinates
// Test whether we hit any anchor.
//BSpline
//with this we avoid creating a new point over the existing one
//Si intentamos crear un nodo en el mismo sitio que el origen, paramos.
return FALSE;
}
}
//BSpline End
case PenTool::MODE_CLICK:
// Start new thread only with button release
if (anchor) {
}
//BSpline
//continuamos una curva existente
if (anchor) {
}
}
//BSpline End
} else {
// Set end anchor here
if (anchor) {
}
}
break;
// End current segment
break;
// End current segment
if (!anchor) { // Snap node only if not hitting anchor
}
//BSpline
//Ocultamos la guia del penultimo nodo al cerrar la curva
}
//BSpline End
break;
// This is allowed, if we just canceled curve
break;
default:
break;
}
break;
break;
//BSpline
//Ocultamos la guia del penultimo nodo al cerrar la curva
}
//BSpline End
if (pc->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;
}
// 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 (pc->waiting_LPE) {
// we have an already created LPE waiting for a path
} 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;
}
{
// green
if (pc->green_bpaths) {
// remove old piecewise green canvasitems
while (pc->green_bpaths) {
}
// one canvas bpath for all of green_curve
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
}
if (pc->green_anchor)
// handles
//BSpline
//Ocultamos los tiradores en modo BSpline y spiro
//BSpline End
} else {
}
if (last_seg) {
//BSpline
//Ocultamos los tiradores en modo BSpline y spiro
if ( cubic &&
{
//BSpline End
} else {
}
}
//BSpline
//Simplemente redibujamos la spiro teniendo en cuenta si el nodo es cusp o symm.
//como es un redibujo simplemente no llamamos a la función global
//sino al final de esta
//BSpline
//Lanzamos solamente el redibujado
//BSpline End
}
{
return;
// green
} else {
// start anchor too
if (pc->green_anchor) {
}
}
// red
}
{
}
{
//BSpline
//Evitamos que si la "red_curve" tiene solo dos puntos -recta- no se pare aqui.
return;
//BSpline
pc->p[1] = pc->red_curve->last_segment()->initialPoint() + (1./3)* (Geom::Point)(pc->red_curve->last_segment()->finalPoint() - pc->red_curve->last_segment()->initialPoint());
//Modificamos el último segmento de la curva verde para que forme el tipo de nodo que deseamos
//We obtain the last segment 4 points in the previous curve
if ( cubic ){
A = (*cubic)[0];
B = (*cubic)[1];
}else
C = pc->green_curve->last_segment()->finalPoint() + (1./3)* (Geom::Point)(pc->green_curve->last_segment()->initialPoint() - pc->green_curve->last_segment()->finalPoint());
D = (*cubic)[3];
}else{
else
C = pc->green_curve->last_segment()->finalPoint() + (1./3)* (Geom::Point)(pc->green_curve->last_segment()->initialPoint() - pc->green_curve->last_segment()->finalPoint());
}
}else{
//we eliminate the last segment
//and we add it again with the recreation
}
}
//Si el último nodo es una union con otra curva
bspline_spiro_start_anchor(pc, false);
}
}
//Spiro Live
}
{
//BSpline
//Evitamos que si la "red_curve" tiene solo dos puntos -recta- no se pare aqui.
return;
//Modificamos el último segmento de la curva verde para que forme el tipo de nodo que deseamos
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( pc->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;
}
}else{
//we eliminate the last segment
//and we add it again with the recreation
}
}
//Si el último nodo es una union con otra curva
bspline_spiro_start_anchor(pc, true);
}
}
}
{
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)) {
}
break;
case GDK_KEY_L:
case GDK_KEY_l:
if (MOD__SHIFT_ONLY(event)) {
}
break;
case GDK_KEY_Return:
case GDK_KEY_KP_Enter:
}
break;
case GDK_KEY_Escape:
// if drawing, cancel, otherwise pass it up for deselecting
pen_cancel (pc);
}
break;
case GDK_KEY_z:
case GDK_KEY_Z:
// if drawing, cancel, otherwise pass it up for undo
pen_cancel (pc);
}
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:
pen_cancel (pc);
} else {
// do nothing; this event should be handled upstream
}
} else {
// Reset red curve
// Destroy topmost green bpath
if (pc->green_bpaths) {
}
// Get last segment
g_warning("pen_handle_key_press, case GDK_KP_Delete: Green curve is empty");
break;
}
// The code below assumes that pc->green_curve has only ONE path !
if ( cubic ) {
} else {
}
//Asignamos el valor a un tercio de distancia del último segmento.
}
: pc->p[3]));
//BSpline
//Eliminamos el último segmento de la curva verde
if (pc->green_bpaths) {
}
}else{
}
//Asignamos el valor de pc->p[1] a el opuesto de el ultimo segmento de la línea verde
if ( cubic ) {
} else {
}
}
//BSpline End
//BSpline
//Redibujamos
//BSpline End
}
break;
default:
break;
}
return ret;
}
{
// Red
// Blue
// Green
while (pc->green_bpaths) {
}
if (pc->green_anchor) {
}
pc->red_curve_is_valid = false;
}
{
pc->p[0] = p;
pc->p[1] = p;
}
/**
* two parameters ("angle %3.2f°, distance %s").
*/
static void spdc_pen_set_angle_distance_status_message(PenTool *const pc, Geom::Point const p, int pc_point_to_compare, gchar const *message)
{
if (angle < 0) {
angle += 360;
}
}
}
//Esta función cambia los colores rojo,verde y azul haciendolos transparentes o no en función de si se usa spiro
{
bool remake_green_bpaths = false;
//If the colour is not defined as trasparent, por example when changing
//from drawing to spiro mode or when selecting the pen tool
//We change the green and red colours to transparent, so this lines are not necessary
//to the drawing with spiro
remake_green_bpaths = true;
}
}else{
//If we come from working with the spiro curve and change the mode the "green_curve" colour is transparent
//since we are not im spiro mode, we assign the original colours
//to the red and the green curve, removing their transparency
remake_green_bpaths = true;
}
}
}
//We erase all the "green_bpaths" to recreate them after with the colour
//transparency recently modified
// remove old piecewise green canvasitems
while (pc->green_bpaths) {
}
// one canvas bpath for all of green_curve
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
}
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(pc->red_bpath), pc->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
}
{
return;
if(!pc->anchor_statusbar)
}
{
using Geom::X;
using Geom::Y;
}
}
{
}
}
{
return;
return;
if(shift)
else
}
{
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;
}else{
}
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
if(cubic){
if(shift)
else
}else{
}
}else{
}
}
if(shift)
else
}
}
{
using Geom::X;
using Geom::Y;
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
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
}
}else{
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment());
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
}
}
}
}
{
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
}
}
}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
}
}
}
}
}
//preparates the curves for its trasformation into BSline curves.
{
return;
//We create the base curve
//If we continuate the existing curve we add it at the start
}
}
//and the red one
}
//cerramos la curva si estan cerca los puntos finales de la curva spiro
}
//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);
}else{
}
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(pc->blue_bpath), pc->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
//We hide the holders that doesn't contribute anything
}else
}else{
//if the curve is empty
}
}
{
return;
// Make copy of old path as it is changed during processing
//Recorremos todos los paths a los que queremos aplicar el efecto, hasta el penúltimo
for(Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) {
//Si está vacío...
continue;
//Itreadores
Geom::Path::const_iterator curve_endit = path_it->end_default(); // this determines when the loop has to stop
//Creamos las lineas rectas que unen todos los puntos del trazado y donde se calcularán
//los puntos clave para los manejadores.
//Esto hace que la curva BSpline no pierda su condición aunque se trasladen
//dichos manejadores
// if the path is closed, maybe we have to stop a bit earlier because the closing line segment has zerolength.
const Geom::Curve &closingline = path_it->back_closed(); // the closing line segment is always of type Geom::LineSegment.
// closingline.isDegenerate() did not work, because it only checks for *exact* zero length, which goes wrong for relative coordinates and rounding errors...
// the closing line segment has zero-length. So stop before that one!
}
}
//Si la curva está cerrada calculamos el punto donde
//en posible caso de que se cierre con una linea recta creando un nodo BSPline
//Recorremos todos los segmentos menos el último
while ( curve_it2 != curve_endit )
{
//previousPointAt3 = pointAt3;
//Calculamos los puntos que dividirían en tres segmentos iguales el path recto de entrada y de salida
if(cubic){
}else{
}
delete in;
//Y hacemos lo propio con el path de salida
//nextPointAt0 = curveOut.valueAt(0);
if(cubic){
}else{
}
delete out;
//La curva BSpline se forma calculando el centro del segmanto de unión
//de el punto situado en las 2/3 partes de el segmento de entrada
//con el punto situado en la posición 1/3 del segmento de salida
//Estos dos puntos ademas estan posicionados en el lugas correspondiente de
//los manejadores de la curva
lineHelper->reset();
delete lineHelper;
//almacenamos el punto del anterior bucle -o el de cierre- que nos hara de principio de curva
previousNode = node;
//Y este hará de final de curva
//añadimos la curva generada a la curva pricipal
curveHelper->reset();
delete curveHelper;
//aumentamos los valores para el siguiente paso en el bucle
++curve_it1;
++curve_it2;
}
//Aberiguamos la ultima parte de la curva correspondiente al último segmento
//Si está cerrada la curva, la cerramos sobre el valor guardado previamente
//Si no finalizamos en el punto final
if(cubic){
}else{
}
delete start;
//Geom::BezierCurve const *bezier = dynamic_cast<Geom::BezierCurve const*>(&*curve_endit);
if(cubic){
}else{
}
delete end;
lineHelper->reset();
delete lineHelper;
//Guardamos el principio de la curva
}else{
delete start;
}
curveHelper->reset();
delete curveHelper;
//y cerramos la curva
}
delete nCurve;
}
}
//Spiro function cloned from lpe-spiro.cpp
{
using Geom::X;
using Geom::Y;
// Make copy of old path as it is changed during processing
int ip = 0;
for(Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) {
continue;
// start of path
{
ip++;
}
// midpoints
Geom::Path::const_iterator curve_endit = path_it->end_default(); // this determines when the loop has to stop
// if the path is closed, maybe we have to stop a bit earlier because the closing line segment has zerolength.
const Geom::Curve &closingline = path_it->back_closed(); // the closing line segment is always of type Geom::LineSegment.
// closingline.isDegenerate() did not work, because it only checks for *exact* zero length, which goes wrong for relative coordinates and rounding errors...
// the closing line segment has zero-length. So stop before that one!
}
}
while ( curve_it2 != curve_endit )
{
/* This deals with the node between curve_it1 and curve_it2.
* Loop to end_default (so without last segment), loop ends when curve_it2 hits the end
* and then curve_it1 points to end or closing segment */
// Determine type of spiro node this is, determined by the tangents (angles) of the curves
// TODO: see if this can be simplified by using /helpers/geom-nodetype.cpp:get_nodetype
{
if (this_is_line && !next_is_line) {
} else if (next_is_line && !this_is_line) {
} else {
}
} else {
}
++curve_it1;
++curve_it2;
ip++;
}
// add last point to the spiropath
// curve_it1 points to the (visually) closing segment. determine the match between first and this last segment (the closing node)
switch (nodetype) {
ip++;
break;
break;
case Geom::NODE_SMOOTH:
break;
}
} else {
// set type to path closer
ip++;
}
// run subpath through spiro
ip = 0;
}
}
//BSpline end
static void spdc_pen_set_subsequent_point(PenTool *const pc, Geom::Point const p, bool statusbar, guint status)
{
// todo: Check callers to see whether 2 <= npoints is guaranteed.
pc->p[2] = p;
pc->p[3] = p;
pc->p[4] = p;
bool is_curve;
// 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
//SpiroLive
//SpiroLive End
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");
//BSpline
_("<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");
}
//BSpline End
}
}
{
pc->p[1] = p;
spdc_pen_set_angle_distance_status_message(pc, p, 0, _("<b>Curve handle</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle"));
pc->p[4] = p;
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 (pc->polylines_paraxial) {
}
++pc->num_clicks;
/// \todo fixme:
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
}
}
{
// don't let the path be finished before we have collected the required number of mouse clicks
return;
}
pc->num_clicks = 0;
if (pc->green_anchor) {
}
}
pc->events_disabled++;
}
pc->events_disabled--;
}
void sp_pen_context_wait_for_LPE_mouse_clicks(PenTool *pc, Inkscape::LivePathEffect::EffectType effect_type,
unsigned int num_clicks, bool use_polylines)
{
return;
}
{
pc->expecting_clicks_for_LPE = 0;
}
//
// 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 (pc->num_clicks == 0) {
// first mouse click
return pen_last_paraxial_dir;
} else {
// subsequent mouse click
}
}
void pen_set_to_nearest_horiz_vert(const PenTool *const pc, Geom::Point &pt, guint const state, bool snap)
{
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 :