pen-context.cpp revision 94e7051137fada5cfdd3b87003492764de63283f
/** \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 "pen-context.h"
#include "sp-namedview.h"
#include "sp-metrics.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
#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
using Inkscape::ControlManager;
static gint sp_pen_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
/*
*BSpline
*Added functions
*/
/*
*Sobrecarga la función "sp_pen_context_set_polyline_mode"
*Le da valor a la nueva propiedad "pc->spiro" que como se auto define indica si estamos en modo spiro
*En el futuro se la dará a "pc->bspline"
*/
//Esta función cambia los colores rojo,verde y azul haciendolos transparentes o no en función de si se usa spiro
//Guarda el valor si se ha pulsado la tecla SHIFT al continuar una curva
static bool saShift = false;
//Preparamos la curva roja para que se muestre según esté pulsada la tecla SHIFT
//Unimos todas las curvas en juego y llamamos a la función doEffect.
//function spiro cloned from lpe-spiro.cpp
//Preparamos la curva roja para que se muestre según esté pulsada la tecla SHIFT
//Unimos todas las curvas en juego y llamamos a la función doEffect.
//function bspline cloned from lpe-bspline.cpp
//BSpline end
static void spdc_pen_set_subsequent_point(SPPenContext *const pc, Geom::Point const p, bool statusbar, guint status = 0);
static bool pen_within_tolerance = false;
static SPDrawContextClass *pen_parent_class;
static int pen_next_paraxial_direction(const SPPenContext *const pc, Geom::Point const &pt, Geom::Point const &origin, guint state);
static void pen_set_to_nearest_horiz_vert(const SPPenContext *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
/**
* Register SPPenContext with Gdk and return its type.
*/
GType sp_pen_context_get_type(void)
{
if (!type) {
sizeof(SPPenContextClass),
sizeof(SPPenContext),
4,
NULL, // value_table
};
}
return type;
}
/**
* Initialize the SPPenContext vtable.
*/
{
}
/**
* Callback to initialize SPPenContext object.
*/
{
pc->events_disabled = 0;
pc->num_clicks = 0;
}
/**
* Callback to destroy the SPPenContext object's members and itself.
*/
{
}
}
}
}
if (pc->expecting_clicks_for_LPE > 0) {
// we received too few clicks to sanely set the parameter path so we remove the LPE from the item
}
}
//BSpline
//we call the function which defines the Spiro modes and the B-spline in the future
//todo: merge to one function only
//BSpline End
}
//BSpline
/*
*.Set the mode of draw now spiro, and later b-splines
*/
}
//BSpline End
/**
* Callback to initialize SPPenContext object.
*/
{
}
// Pen indicators
pc->c0 = mgr.createControl(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), Inkscape::CTRL_TYPE_ADJ_HANDLE);
pc->c1 = mgr.createControl(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), Inkscape::CTRL_TYPE_ADJ_HANDLE);
pc->anchor_statusbar = false;
ec->enableSelectionCue();
}
}
{
pc->num_clicks = 0;
}
/**
* Finalization callback.
*/
{
pen_cancel (pc);
}
}
}
/**
* Callback that sets key to value in pen context.
*/
{
if (name == "mode") {
} else {
}
}
}
/**
* 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.
*/
static void spdc_endpoint_snap_handle(SPPenContext const *const pc, Geom::Point &p, guint const state)
{
} 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) {
if (parent_root_handler) {
}
}
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.
//BSpline
//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;
// In click mode we add point on release
case SP_PEN_CONTEXT_POINT:
case SP_PEN_CONTEXT_CONTROL:
case SP_PEN_CONTEXT_CLOSE:
break;
case SP_PEN_CONTEXT_STOP:
// This is allowed, if we just canceled curve
break;
default:
break;
}
break;
case SP_PEN_CONTEXT_MODE_DRAG:
case SP_PEN_CONTEXT_STOP:
// This is allowed, if we just canceled curve
case SP_PEN_CONTEXT_POINT:
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
// 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
//Esto evita arrastrar los manejadores ya que el punto se crea
//al soltar el botón del ratón.
if((pc->spiro || pc->bspline) && pc->state != SP_PEN_CONTEXT_CLOSE ) pc->state = SP_PEN_CONTEXT_POINT;
//BSpline End
break;
case SP_PEN_CONTEXT_CONTROL:
g_warning("Button down in CONTROL state");
break;
case SP_PEN_CONTEXT_CLOSE:
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 SP_PEN_CONTEXT_POINT:
// 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;
case SP_PEN_CONTEXT_CONTROL:
case SP_PEN_CONTEXT_CLOSE:
// Placing controls is last operation in CLOSE state
break;
case SP_PEN_CONTEXT_STOP:
// This is perfectly valid
break;
default:
break;
}
break;
case SP_PEN_CONTEXT_MODE_DRAG:
case SP_PEN_CONTEXT_POINT:
// 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;
case SP_PEN_CONTEXT_CONTROL:
case SP_PEN_CONTEXT_CLOSE:
// Placing controls is last operation in CLOSE state
// snap the handle
//BSpline
//BSpline End
} else {
}
break;
case SP_PEN_CONTEXT_STOP:
// This is perfectly valid
break;
default:
if (!sp_event_context_knot_mouseover(pc)) {
m.unSetup();
}
break;
}
break;
default:
break;
}
//BSpline
}
}
}
//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
//Si intentamos crear un nodo en el mismo sitio que el origen, paramos.
return FALSE;
}
}
//BSpline End
case SP_PEN_CONTEXT_POINT:
// Start new thread only with button release
if (anchor) {
}
} else {
// Set end anchor here
if (anchor) {
}
}
//BSpline
}
}
//BSpline End
break;
case SP_PEN_CONTEXT_CONTROL:
// End current segment
break;
case SP_PEN_CONTEXT_CLOSE:
// 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;
case SP_PEN_CONTEXT_STOP:
// This is allowed, if we just canceled curve
break;
default:
break;
}
break;
case SP_PEN_CONTEXT_MODE_DRAG:
case SP_PEN_CONTEXT_POINT:
case SP_PEN_CONTEXT_CONTROL:
break;
case SP_PEN_CONTEXT_CLOSE:
//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;
case SP_PEN_CONTEXT_STOP:
// 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
//BSpline End
} else {
}
if (last_seg) {
//BSpline
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
//we redraw spiro
}
//we redraw bspline
}
//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
//Para formar una curva necesitamos un nodo symm en el "lastpoint"
//de esta manera modificamos el final de la "curva_verde" para que sea symm con el pricipio de la "red_curve"
//We obtain the last segment 4 points in the previous curve
if ( cubic ){
A = (*cubic)[0];
B = (*cubic)[1];
D = (*cubic)[3];
}else{
}
}else{
//we eliminate the last segment
//and we add it again with the recreation
}
}
if ( cubic ) {
} else {
}
}
//Para formar una curva bspline necesitamos un nodo cusp en el "lastpoint"
//de esta manera modificamos el final de la "curva_verde" para que sea cusp con el pricipio de la "red_curve"
//Que se quedará recta
//We obtain the last segment 2 points in the previous curve
}else{
//we eliminate the last segment
//and we add it again with the recreation
}
}
//Spiro Live
}
{
//BSpline
//Si no es bspline
return;
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
}
}
//BSpline
//Para formar una recta necesitamos un nodo con manejador en el "lastpoint"
//de esta manera modificamos el final de la "curva_verde" para que tenga manejador
using Geom::X;
using Geom::Y;
//We obtain the last segment 4 points in the previous curve
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
}
}
}
{
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:
if (!MOD__CTRL) { // not ctrl
if (MOD__ALT) { // alt
}
else { // no alt
}
}
break;
case GDK_KEY_Up: // move last point up
case GDK_KEY_KP_Up:
if (!MOD__CTRL) { // not ctrl
if (MOD__ALT) { // alt
}
else { // no alt
}
}
break;
case GDK_KEY_Right: // move last point right
case GDK_KEY_KP_Right:
if (!MOD__CTRL) { // not ctrl
if (MOD__ALT) { // alt
}
else { // no alt
}
}
break;
case GDK_KEY_Down: // move last point down
case GDK_KEY_KP_Down:
if (!MOD__CTRL) { // not ctrl
if (MOD__ALT) { // alt
}
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) {
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) {
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) {
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) {
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) {
}
break;
case GDK_KEY_L:
case GDK_KEY_l:
if (MOD__SHIFT_ONLY) {
}
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) {
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
//BSpline
pen_cancel (pc);
}
//BSpline End
// 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 !
} else {
}
: pc->p[3] ));
//BSpline
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
}
//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(SPPenContext *const pc, Geom::Point const p, int pc_point_to_compare, gchar const *message)
{
}
//BSpline Set Functions
//Creates a new curve resetting the original
{
return ret;
}
//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);
}
//Preparamos la curva roja para que se muestre según esté pulsada la tecla SHIFT
{
if(Shift){
//Creamos un nodo CUSP
}
//Continuamos la curva en modo CUSP
//Guardamos el valor de inicio en cusp para que no se redibuje como SYMM
saShift = true;
}
}else{
//Symm nodo
using Geom::X;
using Geom::Y;
saShift = false;
}
//Damos valores a los puntos de la curva roja para que generen un nodo SYMM
//Les damos valor
}
//Continuamos la curva en modo SPIRO
if( saShift == false && pc->sa && !pc->sa->curve->is_empty() && !pc->ea && pc->green_curve->is_empty()){
}
if(cubic){
}
}
//Nos aseguramos que el primer nodo sea SYMM con el ultimo segmento de la curva verde
}
//Damos valor original a la variable por si se necesita de nuevo
saShift = false;
}
//Si cerramos sobre otra curva ponemos simetrico a esta el manejador del punto de cierre
if(pc->anchor_statusbar && pc->sa && !Geom::are_near(pc->sa->dp, pc->red_curve->first_segment()->finalPoint())){
}
if(cubic){
}
}
//Lo mismpo pero cerrando sobre la curva inicial
if(cubic){
}
}
}
}
//Unimos todas las curvas en juego y llamamos a la función doEffect.
{
//We create the base curve
//If we continuate the existing curve we add it at the start
}
}
//We add also the green curve
//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 LPEspiro(lpeobj) );
//spr->doEffect(curve);
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{
//if the curve is empty
}
}
//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;
}
}
//Unimos todas las curvas en juego y llamamos a la función doEffect.
{
if(Shift){
using Geom::X;
using Geom::Y;
//Continuamos la curva en modo CUSP
//Guardamos el valor de inicio en cusp para que no se redibuje como SYMM
saShift = true;
}
//NODO CUSP formado por nodo SMOOTH
//solo mobemos el manejador del nodo final de cada segmento
//Es suficiente para mostrar el nodo como CUSP
//Usamos 5 puntos
}
}else{
saShift = false;
}
//Damos valor original a la variable por si se necesita de nuevo
saShift = false;
}
//Modo Bspline formado por nodos CUSP
}
}
}
}
//preparates the curves for its trasformation into BSline curves.
{
//We create the base curve
//If we continuate the existing curve we add it at the start
}
}
//We add also the green curve
//and the red one
}else{
}
}
//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);
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{
//if the curve is empty
}
}
{
using Geom::X;
using Geom::Y;
return;
// Make copy of old path as it is changed during processing
//Sbasis
//curves
//Curvas temporales
//Puntos a usar. Ponemos todos los posibles para hacer más inteligible el código
//Geom::Point previousPointAt3(0,0);
//Geom::Point nextPointAt0(0,0);
//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
//Las lineas rectas forman nodos BSpline
//Las curvas forman nodos CUSP
bool isBSpline = true;
//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
//este no cambia.
//Si la curva está cerrada calculamos el punto donde
//en posible caso de que se cierre con una linea recta creando un nodo BSPline
isBSpline = false;
//Calculamos el nodo de inicio BSpline
lineHelper->reset();
//Guardamos el principio de la curva
//Definimos el punto de inicio original de la curva resultante
}else{
isBSpline = true;
//Guardamos el principio de la curva
//Definimos el punto de inicio original de la curva resultante
}
//Recorremos todos los segmentos menos el último
while ( curve_it2 != curve_endit )
{
//Damos valor a el objeto SBasis para el path de entrada y el de salida
//previousPointAt3 = pointAt3;
//Calculamos los puntos que dividirían en tres segmentos iguales el path recto de entrada y de salida
//Y hacemos lo propio con el path de salida
//nextPointAt0 = curveOut.valueAt(0);
//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();
//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
//Vemos si el nodo es BSpline o CUSP
//Averiguamos si el punto de union tiene manejadores
isBSpline = false;
isBSpline = false;
//Si no tiene manejador, tenemos que generar la curva con nodo final CUSP
if(!isBSpline ){
//Definimos como nodo el final del segmento de entrada
isBSpline = true;
}
//añadimos la curva generada a la curva pricipal
curveHelper->reset();
//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
}else{
isBSpline = true;
}
//añadimos este último segmento
//y cerramos la curva
}
//Limpiamos
lineHelper->reset();
curveHelper->reset();
}
delete in;
delete out;
delete end;
delete lineHelper;
delete curveHelper;
//Todo: remove?
//delete SBasisIn;
//delete SBasisOut;
//delete SBasisEnd;
//delete SBasisHelper;
}
//BSpline end
static void spdc_pen_set_subsequent_point(SPPenContext *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;
//BSpline
}
}
//BSpline End
/// \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;
saShift = false;
}
if (pc->green_anchor) {
}
}
pc->events_disabled++;
}
pc->events_disabled--;
}
void sp_pen_context_wait_for_LPE_mouse_clicks(SPPenContext *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 SPPenContext *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 :