measure-context.cpp revision 24be9baeb3585155f4b723dbda0726a4930b5c05
/*
* Our nice measuring tool
*
* Authors:
* Felipe Correa da Silva Sanches <juca@members.fsf.org>
* Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2011 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <gdk/gdkkeysyms.h>
#include "macros.h"
#include "sp-shape.h"
#include "sp-text.h"
#include "sp-flowtext.h"
#include "text-editing.h"
#include "display/sp-ctrlline.h"
#include "display/sodipodi-ctrl.h"
#include "display/sp-canvas-item.h"
#include "display/sp-canvas-util.h"
#include "desktop.h"
#include "document.h"
#include "pixmaps/cursor-measure.xpm"
#include "preferences.h"
#include "inkscape.h"
#include "desktop-handles.h"
#include "measure-context.h"
#include "draw-context.h"
#include "display/canvas-text.h"
#include "path-chemistry.h"
#include "snap.h"
#include "sp-namedview.h"
static gint sp_measure_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event);
static SPEventContextClass *parent_class;
static bool within_tolerance = false;
{
if (!type) {
sizeof(SPMeasureContextClass),
sizeof(SPMeasureContext),
4,
NULL, // value_table
};
type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPMeasureContext", &info, static_cast<GTypeFlags>(0));
}
return type;
}
{
}
{
}
{
ec->enableGrDrag(false);
}
}
{
if (parent_class->setup) {
}
}
static gint sp_measure_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event)
{
if (parent_class->item_handler) {
}
return ret;
}
{
} else {
}
}
void calculate_intersections(SPDesktop * /*desktop*/, SPItem* item, Geom::PathVector *lineseg, SPCurve *curve, std::vector<Geom::Point> *intersections)
{
// Find all intersections of the control-line with this shape
// Reconstruct and store the points of intersection
#if 0
//TODO: consider only visible intersections
double eps = 0.0001;
}
#else
#endif
}
}
{
case GDK_BUTTON_PRESS:
{
// save drag origin
within_tolerance = true;
}
m.unSetup();
GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK,
break;
}
case GDK_MOTION_NOTIFY:
{
m.unSetup();
}
} else {
if ( within_tolerance
break; // do not drag if we're within tolerance from origin
}
// Once the user has moved farther than tolerance from the original location
// (indicating they intend to move the object, not click), then always process the
// motion notify coordinates as given (no snapping back to origin)
within_tolerance = false;
//clear previous temporary canvas items, we'll draw new ones
}
} else {
m.unSetup();
}
}
//draw control line
//TODO: calculate NPOINTS
//800 seems to be a good value for 800x600 resolution
#define NPOINTS 800
for (double i = 0; i < NPOINTS; i++) {
}
// TODO: Felipe, why don't you simply iterate over all items, and test whether their bounding boxes intersect
// with the measurement line, instead of interpolating? E.g. bbox_of_measurement_line.intersects(*bbox_of_item).
// That's also how the object-snapper works, see _findCandidates() in object-snapper.cpp.
//select elements crossed by line segment:
if (!ignore_1st_and_last) {
}
// TODO switch to a different variable name. The single letter 'l' is easy to misread.
if (SP_IS_SHAPE(item)) {
} else {
do {
break;
}
// get path from iter to iter_next:
if (!curve) {
continue; // error converting this glyph
}
continue;
}
break;
}
} while (true);
}
}
}
if (!ignore_1st_and_last) {
}
//sort intersections
}
// Display the intersection indicator (i.e. the cross)
"anchor", GTK_ANCHOR_CENTER,
"size", 8.0,
"stroked", TRUE,
"stroke_color", 0xff0000ff,
"mode", SP_KNOT_MODE_XOR,
"shape", SP_KNOT_SHAPE_CROSS,
NULL );
}
if (intersections.size() > 0) {
previous_point = intersections[0];
}
//TODO: shift label a few pixels in the y coordinate
// TODO cleanup memory, Glib::ustring, etc.:
SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, desktop->doc2dt(measure_text_pos), measure_str);
}
{
// TODO cleanup memory, Glib::ustring, etc.:
SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, end_point + desktop->w2d(Geom::Point(3*fontsize, fontsize)), angle_str);
}
{
SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, end_point + desktop->w2d(Geom::Point(3*fontsize, -fontsize)), totallength_str);
}
Geom::Point normal = desktop->w2d(Geom::unit_vector(Geom::rot90(desktop->d2w(end_point - start_point))));
sp_ctrlline_set_coords(SP_CTRLLINE(control_line), desktop->doc2dt(intersections[0]) + normal*60, desktop->doc2dt(intersections[intersections.size()-1]) + normal*60);
sp_ctrlline_set_coords(SP_CTRLLINE(control_line), desktop->doc2dt(intersections[0]), desktop->doc2dt(intersections[0]) + normal*65);
sp_ctrlline_set_coords(SP_CTRLLINE(control_line), desktop->doc2dt(intersections[intersections.size()-1]), desktop->doc2dt(intersections[intersections.size()-1]) + normal*65);
// TODO cleanup memory, Glib::ustring, etc.:
SPCanvasItem *canvas_tooltip = sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, desktop->doc2dt((intersections[0] + intersections[intersections.size()-1])/2) + normal*60, total_str);
}
}
break;
}
case GDK_BUTTON_RELEASE:
{
//clear all temporary canvas items related to the measurement tool.
}
}
xp = 0;
yp = 0;
break;
}
default:
break;
}
if (!ret) {
if (parent_class->root_handler) {
}
}
return ret;
}
/*
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 :