lpe-tool-context.cpp revision 24be9baeb3585155f4b723dbda0726a4930b5c05
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * LPEToolContext: a context for a generic tool composed of subtools that are given by LPEs
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Authors:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Maximilian Albert <maximilian.albert@gmail.com>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Lauris Kaplinski <lauris@kaplinski.com>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Abhishek Sharma
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright (C) 1998 The Free Software Foundation
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright (C) 1999-2005 authors
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright (C) 2001-2002 Ximian, Inc.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright (C) 2008 Maximilian Albert
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Released under GNU GPL, read the file 'COPYING' for more information
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#ifdef HAVE_CONFIG_H
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "config.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#endif
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <2geom/sbasis-geometric.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <gdk/gdkkeysyms.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "macros.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "pixmaps/cursor-crosshairs.xpm"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <gtk/gtk.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "desktop.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "message-context.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "preferences.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "shape-editor.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "selection.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "desktop-handles.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "document.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "display/curve.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "display/canvas-bpath.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "display/canvas-text.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "message-stack.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "sp-path.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "helper/units.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "lpe-tool-context.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic void sp_lpetool_context_class_init(SPLPEToolContextClass *klass);
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic void sp_lpetool_context_init(SPLPEToolContext *erc);
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic void sp_lpetool_context_dispose(GObject *object);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic void sp_lpetool_context_setup(SPEventContext *ec);
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic void sp_lpetool_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *);
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic gint sp_lpetool_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event);
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic gint sp_lpetool_context_root_handler(SPEventContext *ec, GdkEvent *event);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowvoid sp_lpetool_context_selection_changed(Inkscape::Selection *selection, gpointer data);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowconst int num_subtools = 8;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowSubtoolEntry lpesubtools[] = {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // this must be here to account for the "all inactive" action
4bff34e37def8a90f9194d81bc345c52ba20086athurlow {Inkscape::LivePathEffect::INVALID_LPE, "draw-geometry-inactive"},
4bff34e37def8a90f9194d81bc345c52ba20086athurlow {Inkscape::LivePathEffect::LINE_SEGMENT, "draw-geometry-line-segment"},
4bff34e37def8a90f9194d81bc345c52ba20086athurlow {Inkscape::LivePathEffect::CIRCLE_3PTS, "draw-geometry-circle-from-three-points"},
4bff34e37def8a90f9194d81bc345c52ba20086athurlow {Inkscape::LivePathEffect::CIRCLE_WITH_RADIUS, "draw-geometry-circle-from-radius"},
4bff34e37def8a90f9194d81bc345c52ba20086athurlow {Inkscape::LivePathEffect::PARALLEL, "draw-geometry-line-parallel"},
4bff34e37def8a90f9194d81bc345c52ba20086athurlow {Inkscape::LivePathEffect::PERP_BISECTOR, "draw-geometry-line-perpendicular"},
4bff34e37def8a90f9194d81bc345c52ba20086athurlow {Inkscape::LivePathEffect::ANGLE_BISECTOR, "draw-geometry-angle-bisector"},
4bff34e37def8a90f9194d81bc345c52ba20086athurlow {Inkscape::LivePathEffect::MIRROR_SYMMETRY, "draw-geometry-mirror"}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow};
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic SPPenContextClass *lpetool_parent_class = 0;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowGType sp_lpetool_context_get_type(void)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow static GType type = 0;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!type) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow GTypeInfo info = {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow sizeof(SPLPEToolContextClass),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow 0, // base_init
4bff34e37def8a90f9194d81bc345c52ba20086athurlow 0, // base_finalize
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (GClassInitFunc)sp_lpetool_context_class_init,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow 0, // class_finalize
4bff34e37def8a90f9194d81bc345c52ba20086athurlow 0, // class_data
4bff34e37def8a90f9194d81bc345c52ba20086athurlow sizeof(SPLPEToolContext),
4bff34e37def8a90f9194d81bc345c52ba20086athurlow 0, // n_preallocs
91d632c867159b669d90fc7e172295433d0519efgwr (GInstanceInitFunc)sp_lpetool_context_init,
91d632c867159b669d90fc7e172295433d0519efgwr 0 // value_table
91d632c867159b669d90fc7e172295433d0519efgwr };
91d632c867159b669d90fc7e172295433d0519efgwr type = g_type_register_static(SP_TYPE_PEN_CONTEXT, "SPLPEToolContext", &info, static_cast<GTypeFlags>(0));
91d632c867159b669d90fc7e172295433d0519efgwr }
91d632c867159b669d90fc7e172295433d0519efgwr return type;
91d632c867159b669d90fc7e172295433d0519efgwr}
91d632c867159b669d90fc7e172295433d0519efgwr
91d632c867159b669d90fc7e172295433d0519efgwrstatic void
91d632c867159b669d90fc7e172295433d0519efgwrsp_lpetool_context_class_init(SPLPEToolContextClass *klass)
91d632c867159b669d90fc7e172295433d0519efgwr{
91d632c867159b669d90fc7e172295433d0519efgwr GObjectClass *object_class = (GObjectClass *) klass;
91d632c867159b669d90fc7e172295433d0519efgwr SPEventContextClass *event_context_class = (SPEventContextClass *) klass;
91d632c867159b669d90fc7e172295433d0519efgwr
91d632c867159b669d90fc7e172295433d0519efgwr lpetool_parent_class = (SPPenContextClass*)g_type_class_peek_parent(klass);
91d632c867159b669d90fc7e172295433d0519efgwr
91d632c867159b669d90fc7e172295433d0519efgwr object_class->dispose = sp_lpetool_context_dispose;
91d632c867159b669d90fc7e172295433d0519efgwr
91d632c867159b669d90fc7e172295433d0519efgwr event_context_class->setup = sp_lpetool_context_setup;
91d632c867159b669d90fc7e172295433d0519efgwr event_context_class->set = sp_lpetool_context_set;
91d632c867159b669d90fc7e172295433d0519efgwr event_context_class->root_handler = sp_lpetool_context_root_handler;
91d632c867159b669d90fc7e172295433d0519efgwr event_context_class->item_handler = sp_lpetool_context_item_handler;
91d632c867159b669d90fc7e172295433d0519efgwr}
91d632c867159b669d90fc7e172295433d0519efgwr
91d632c867159b669d90fc7e172295433d0519efgwrstatic void
91d632c867159b669d90fc7e172295433d0519efgwrsp_lpetool_context_init(SPLPEToolContext *lc)
91d632c867159b669d90fc7e172295433d0519efgwr{
91d632c867159b669d90fc7e172295433d0519efgwr lc->cursor_shape = cursor_crosshairs_xpm;
91d632c867159b669d90fc7e172295433d0519efgwr lc->hot_x = 7;
91d632c867159b669d90fc7e172295433d0519efgwr lc->hot_y = 7;
91d632c867159b669d90fc7e172295433d0519efgwr
91d632c867159b669d90fc7e172295433d0519efgwr lc->canvas_bbox = NULL;
91d632c867159b669d90fc7e172295433d0519efgwr lc->measuring_items = new std::map<SPPath *, SPCanvasItem*>;
91d632c867159b669d90fc7e172295433d0519efgwr
91d632c867159b669d90fc7e172295433d0519efgwr new (&lc->sel_changed_connection) sigc::connection();
91d632c867159b669d90fc7e172295433d0519efgwr}
91d632c867159b669d90fc7e172295433d0519efgwr
91d632c867159b669d90fc7e172295433d0519efgwrstatic void
91d632c867159b669d90fc7e172295433d0519efgwrsp_lpetool_context_dispose(GObject *object)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(object);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow delete lc->shape_editor;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
91d632c867159b669d90fc7e172295433d0519efgwr if (lc->canvas_bbox) {
91d632c867159b669d90fc7e172295433d0519efgwr gtk_object_destroy(GTK_OBJECT(lc->canvas_bbox));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->canvas_bbox = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lpetool_delete_measuring_items(lc);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow delete lc->measuring_items;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->measuring_items = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->sel_changed_connection.disconnect();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->sel_changed_connection.~connection();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (lc->_lpetool_message_context) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow delete lc->_lpetool_message_context;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow G_OBJECT_CLASS(lpetool_parent_class)->dispose(object);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic void
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsp_lpetool_context_setup(SPEventContext *ec)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(ec);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (((SPEventContextClass *) lpetool_parent_class)->setup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ((SPEventContextClass *) lpetool_parent_class)->setup(ec);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Inkscape::Selection *selection = sp_desktop_selection (ec->desktop);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPItem *item = selection->singleItem();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->sel_changed_connection.disconnect();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->sel_changed_connection =
4bff34e37def8a90f9194d81bc345c52ba20086athurlow selection->connectChanged(sigc::bind(sigc::ptr_fun(&sp_lpetool_context_selection_changed), (gpointer)lc));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->shape_editor = new ShapeEditor(ec->desktop);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lpetool_context_switch_mode(lc, Inkscape::LivePathEffect::INVALID_LPE);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lpetool_context_reset_limiting_bbox(lc);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lpetool_create_measuring_items(lc);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow// TODO temp force:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ec->enableSelectionCue();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (item) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->shape_editor->set_item(item, SH_NODEPATH);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->shape_editor->set_item(item, SH_KNOTHOLDER);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (prefs->getBool("/tools/lpetool/selcue")) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ec->enableSelectionCue();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->_lpetool_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack());
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/**
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Callback that processes the "changed" signal on the selection;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * destroys old and creates new nodepath and reassigns listeners to the new selected item's repr.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowvoid sp_lpetool_context_selection_changed(Inkscape::Selection *selection, gpointer data)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(data);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->shape_editor->unset_item(SH_KNOTHOLDER);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPItem *item = selection->singleItem();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->shape_editor->set_item(item, SH_KNOTHOLDER);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic void
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsp_lpetool_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (val->getEntryName() == "mode") {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Inkscape::Preferences::get()->setString("/tools/geometric/mode", "drag");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SP_PEN_CONTEXT(ec)->mode = SP_PEN_CONTEXT_MODE_DRAG;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow //pass on up to parent class to handle common attributes.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if ( lpetool_parent_class->set ) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lpetool_parent_class->set(ec, key, val);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic gint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsp_lpetool_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gint ret = FALSE;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (event->type) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case GDK_BUTTON_PRESS:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // select the clicked item but do nothing else
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Inkscape::Selection * const selection = sp_desktop_selection(ec->desktop);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow selection->clear();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow selection->add(item);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = TRUE;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case GDK_BUTTON_RELEASE:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // TODO: do we need to catch this or can we pass it on to the parent handler?
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = TRUE;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow default:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!ret) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (((SPEventContextClass *) lpetool_parent_class)->item_handler)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = ((SPEventContextClass *) lpetool_parent_class)->item_handler(ec, item, event);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return ret;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowgint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsp_lpetool_context_root_handler(SPEventContext *event_context, GdkEvent *event)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(event_context);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPDesktop *desktop = event_context->desktop;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Inkscape::Selection *selection = sp_desktop_selection (desktop);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow bool ret = false;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (sp_pen_context_has_waiting_LPE(lc)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // quit when we are waiting for a LPE to be applied
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = ((SPEventContextClass *) lpetool_parent_class)->root_handler(event_context, event);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return ret;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (event->type) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case GDK_BUTTON_PRESS:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (event->button.button == 1 && !event_context->space_panning) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (lc->mode == Inkscape::LivePathEffect::INVALID_LPE) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // don't do anything for now if we are inactive (except clearing the selection
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // since this was a click into empty space)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow selection->clear();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Choose a construction tool from the toolbar."));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = true;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // save drag origin
4bff34e37def8a90f9194d81bc345c52ba20086athurlow event_context->xp = (gint) event->button.x;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow event_context->yp = (gint) event->button.y;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow event_context->within_tolerance = true;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow using namespace Inkscape::LivePathEffect;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int mode = prefs->getInt("/tools/lpetool/mode");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow EffectType type = lpesubtools[mode].type;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow //bool over_stroke = lc->shape_editor->is_over_stroke(Geom::Point(event->button.x, event->button.y), true);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow sp_pen_context_wait_for_LPE_mouse_clicks(lc, type, Inkscape::LivePathEffect::Effect::acceptsNumClicks(type));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // we pass the mouse click on to pen tool as the first click which it should collect
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = ((SPEventContextClass *) lpetool_parent_class)->root_handler(event_context, event);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case GDK_BUTTON_RELEASE:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /**
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow **/
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case GDK_KEY_PRESS:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /**
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (get_group0_keyval (&event->key)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow **/
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case GDK_KEY_RELEASE:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /**
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (get_group0_keyval(&event->key)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case GDK_Control_L:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case GDK_Control_R:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow dc->_message_context->clear();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow default:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow **/
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow default:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!ret) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (((SPEventContextClass *) lpetool_parent_class)->root_handler) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = ((SPEventContextClass *) lpetool_parent_class)->root_handler(event_context, event);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return ret;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Finds the index in the list of geometric subtools corresponding to the given LPE type.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Returns -1 if no subtool is found.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowlpetool_mode_to_index(Inkscape::LivePathEffect::EffectType const type) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow for (int i = 0; i < num_subtools; ++i) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (lpesubtools[i].type == type) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return i;
91d632c867159b669d90fc7e172295433d0519efgwr }
91d632c867159b669d90fc7e172295433d0519efgwr }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return -1;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Checks whether an item has a construction applied as LPE and if so returns the index in
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * lpesubtools of this construction
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint lpetool_item_has_construction(SPLPEToolContext */*lc*/, SPItem *item)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!SP_IS_LPE_ITEM(item)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return -1;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Inkscape::LivePathEffect::Effect* lpe = sp_lpe_item_get_current_lpe(SP_LPE_ITEM(item));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!lpe) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return -1;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return lpetool_mode_to_index(lpe->effectType());
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Attempts to perform the construction of the given type (i.e., to apply the corresponding LPE) to
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * a single selected item. Returns whether we succeeded.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowbool
4bff34e37def8a90f9194d81bc345c52ba20086athurlowlpetool_try_construction(SPLPEToolContext *lc, Inkscape::LivePathEffect::EffectType const type)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Inkscape::Selection *selection = sp_desktop_selection(lc->desktop);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPItem *item = selection->singleItem();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // TODO: should we check whether type represents a valid geometric construction?
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (item && SP_IS_LPE_ITEM(item) && Inkscape::LivePathEffect::Effect::acceptsNumClicks(type) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Inkscape::LivePathEffect::Effect::createAndApply(type, sp_desktop_document(lc->desktop), item);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return true;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return false;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowvoid
4bff34e37def8a90f9194d81bc345c52ba20086athurlowlpetool_context_switch_mode(SPLPEToolContext *lc, Inkscape::LivePathEffect::EffectType const type)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int index = lpetool_mode_to_index(type);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (index != -1) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->mode = type;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->desktop->setToolboxSelectOneValue ("lpetool_mode_action", index);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow g_warning ("Invalid mode selected: %d", type);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowvoid
4bff34e37def8a90f9194d81bc345c52ba20086athurlowlpetool_get_limiting_bbox_corners(SPDocument *document, Geom::Point &A, Geom::Point &B) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Geom::Coord w = document->getWidth();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Geom::Coord h = document->getHeight();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow double ulx = prefs->getDouble("/tools/lpetool/bbox_upperleftx", 0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow double uly = prefs->getDouble("/tools/lpetool/bbox_upperlefty", 0);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow double lrx = prefs->getDouble("/tools/lpetool/bbox_lowerrightx", w);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow double lry = prefs->getDouble("/tools/lpetool/bbox_lowerrighty", h);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow A = Geom::Point(ulx, uly);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow B = Geom::Point(lrx, lry);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Reads the limiting bounding box from preferences and draws it on the screen
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow// TODO: Note that currently the bbox is not user-settable; we simply use the page borders
4bff34e37def8a90f9194d81bc345c52ba20086athurlowvoid
4bff34e37def8a90f9194d81bc345c52ba20086athurlowlpetool_context_reset_limiting_bbox(SPLPEToolContext *lc)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (lc->canvas_bbox) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gtk_object_destroy(GTK_OBJECT(lc->canvas_bbox));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->canvas_bbox = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!prefs->getBool("/tools/lpetool/show_bbox", true))
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPDocument *document = sp_desktop_document(lc->desktop);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Geom::Point A, B;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lpetool_get_limiting_bbox_corners(document, A, B);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Geom::Affine doc2dt(lc->desktop->doc2dt());
4bff34e37def8a90f9194d81bc345c52ba20086athurlow A *= doc2dt;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow B *= doc2dt;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Geom::Rect rect(A, B);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPCurve *curve = SPCurve::new_from_rect(rect);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->canvas_bbox = sp_canvas_bpath_new (sp_desktop_controls(lc->desktop), curve);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(lc->canvas_bbox), 0x0000ffff, 0.8, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT, 5, 5);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic void
4bff34e37def8a90f9194d81bc345c52ba20086athurlowset_pos_and_anchor(SPCanvasText *canvas_text, const Geom::Piecewise<Geom::D2<Geom::SBasis> > &pwd2,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow const double t, const double length, bool /*use_curvature*/ = false)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow using namespace Geom;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Piecewise<D2<SBasis> > pwd2_reparam = arc_length_parametrization(pwd2, 2 , 0.1);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow double t_reparam = pwd2_reparam.cuts.back() * t;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Point pos = pwd2_reparam.valueAt(t_reparam);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Point dir = unit_vector(derivative(pwd2_reparam).valueAt(t_reparam));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Point n = -rot90(dir);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // double angle = Geom::angle_between(dir, Point(1,0));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow sp_canvastext_set_coords(canvas_text, pos + n * length);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // Canvastext currently no longer allows for setting a custom anchor position,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // This functionality was broken as of rev. #10331, and completely removed as of 2012-01-01
4bff34e37def8a90f9194d81bc345c52ba20086athurlow //sp_canvastext_set_anchor(canvas_text, std::sin(angle), -std::cos(angle));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowvoid
4bff34e37def8a90f9194d81bc345c52ba20086athurlowlpetool_create_measuring_items(SPLPEToolContext *lc, Inkscape::Selection *selection)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!selection) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow selection = sp_desktop_selection(lc->desktop);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
91d632c867159b669d90fc7e172295433d0519efgwr Inkscape::Preferences *prefs = Inkscape::Preferences::get();
91d632c867159b669d90fc7e172295433d0519efgwr bool show = prefs->getBool("/tools/lpetool/show_measuring_info", true);
91d632c867159b669d90fc7e172295433d0519efgwr
91d632c867159b669d90fc7e172295433d0519efgwr SPPath *path;
91d632c867159b669d90fc7e172295433d0519efgwr SPCurve *curve;
91d632c867159b669d90fc7e172295433d0519efgwr SPCanvasText *canvas_text;
91d632c867159b669d90fc7e172295433d0519efgwr SPCanvasGroup *tmpgrp = sp_desktop_tempgroup(lc->desktop);
91d632c867159b669d90fc7e172295433d0519efgwr gchar *arc_length;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow double lengthval;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow for (GSList const *i = selection->itemList(); i != NULL; i = i->next) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (SP_IS_PATH(i->data)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow path = SP_PATH(i->data);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow curve = SP_SHAPE(path)->getCurve();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = paths_to_pw(curve->get_pathvector());
4bff34e37def8a90f9194d81bc345c52ba20086athurlow canvas_text = (SPCanvasText *) sp_canvastext_new(tmpgrp, lc->desktop, Geom::Point(0,0), "");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!show)
91d632c867159b669d90fc7e172295433d0519efgwr sp_canvas_item_hide(SP_CANVAS_ITEM(canvas_text));
91d632c867159b669d90fc7e172295433d0519efgwr
91d632c867159b669d90fc7e172295433d0519efgwr SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX));
91d632c867159b669d90fc7e172295433d0519efgwr SPUnit unit = sp_unit_get_by_id(unitid);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lengthval = Geom::length(pwd2);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gboolean success;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px");
91d632c867159b669d90fc7e172295433d0519efgwr sp_canvastext_set_text (canvas_text, arc_length);
91d632c867159b669d90fc7e172295433d0519efgwr set_pos_and_anchor(canvas_text, pwd2, 0.5, 10);
91d632c867159b669d90fc7e172295433d0519efgwr // TODO: must we free arc_length?
91d632c867159b669d90fc7e172295433d0519efgwr (*lc->measuring_items)[path] = SP_CANVAS_ITEM(canvas_text);
91d632c867159b669d90fc7e172295433d0519efgwr }
91d632c867159b669d90fc7e172295433d0519efgwr }
91d632c867159b669d90fc7e172295433d0519efgwr}
91d632c867159b669d90fc7e172295433d0519efgwr
4bff34e37def8a90f9194d81bc345c52ba20086athurlowvoid
4bff34e37def8a90f9194d81bc345c52ba20086athurlowlpetool_delete_measuring_items(SPLPEToolContext *lc)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow std::map<SPPath *, SPCanvasItem*>::iterator i;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow for (i = lc->measuring_items->begin(); i != lc->measuring_items->end(); ++i) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gtk_object_destroy(GTK_OBJECT(i->second));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow lc->measuring_items->clear();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowvoid
4bff34e37def8a90f9194d81bc345c52ba20086athurlowlpetool_update_measuring_items(SPLPEToolContext *lc)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Inkscape::Preferences *prefs = Inkscape::Preferences::get();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPPath *path;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPCurve *curve;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow double lengthval;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gchar *arc_length;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow std::map<SPPath *, SPCanvasItem*>::iterator i;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow for (i = lc->measuring_items->begin(); i != lc->measuring_items->end(); ++i) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow path = i->first;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow curve = SP_SHAPE(path)->getCurve();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = Geom::paths_to_pw(curve->get_pathvector());
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPUnitId unitid = static_cast<SPUnitId>(prefs->getInt("/tools/lpetool/unitid", SP_UNIT_PX));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SPUnit unit = sp_unit_get_by_id(unitid);
91d632c867159b669d90fc7e172295433d0519efgwr lengthval = Geom::length(pwd2);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow gboolean success;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow success = sp_convert_distance(&lengthval, &sp_unit_get_by_id(SP_UNIT_PX), &unit);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow arc_length = g_strdup_printf("%.2f %s", lengthval, success ? sp_unit_get_abbreviation(&unit) : "px");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow sp_canvastext_set_text (SP_CANVASTEXT(i->second), arc_length);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow set_pos_and_anchor(SP_CANVASTEXT(i->second), pwd2, 0.5, 10);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow // TODO: must we free arc_length?
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlowvoid
4bff34e37def8a90f9194d81bc345c52ba20086athurlowlpetool_show_measuring_info(SPLPEToolContext *lc, bool show)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow std::map<SPPath *, SPCanvasItem*>::iterator i;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow for (i = lc->measuring_items->begin(); i != lc->measuring_items->end(); ++i) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (show) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow sp_canvas_item_show(i->second);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow sp_canvas_item_hide(i->second);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow Local Variables:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow mode:c++
4bff34e37def8a90f9194d81bc345c52ba20086athurlow c-file-style:"stroustrup"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
4bff34e37def8a90f9194d81bc345c52ba20086athurlow indent-tabs-mode:nil
4bff34e37def8a90f9194d81bc345c52ba20086athurlow fill-column:99
4bff34e37def8a90f9194d81bc345c52ba20086athurlow End:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow*/
4bff34e37def8a90f9194d81bc345c52ba20086athurlow// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
4bff34e37def8a90f9194d81bc345c52ba20086athurlow