measure-tool.cpp revision 9ba77856a8823f85b53c0a861d220cd0347f2754
/*
* 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 <boost/none_t.hpp>
#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 "ui/tools/measure-tool.h"
#include "ui/tools/freehand-base.h"
#include "display/canvas-text.h"
#include "path-chemistry.h"
#include "snap.h"
#include "sp-namedview.h"
#include "enums.h"
#include "ui/control-manager.h"
#include "knot-enums.h"
using Inkscape::ControlManager;
using Inkscape::CTLINE_SECONDARY;
#include "ui/tool-factory.h"
namespace Inkscape {
namespace UI {
namespace Tools {
namespace {
return new MeasureTool();
}
bool measureContextRegistered = ToolFactory::instance().registerObject("/tools/measure", createMeasureContext);
}
return MeasureTool::prefsPath;
}
namespace
{
/**
* Simple class to use for removing label overlap.
*/
class LabelPlacement {
public:
double lengthVal;
double offset;
};
{
} else {
}
}
void repositionOverlappingLabels(std::vector<LabelPlacement> &placements, SPDesktop *desktop, Geom::Point const &normal, double fontsize)
{
double border = 3;
{
}
// Using index since vector may be re-ordered as we go.
// Starting at one, since the first item can't overlap itself
bool changed = false;
do {
changed = false;
bool overlaps = false;
overlaps = true;
}
}
if (overlaps) {
changed = true;
}
} while (changed);
}
}
/**
* Calculates where to place the anchor for the display text and arc.
*
* @param desktop the desktop that is being used.
* @param angle the angle to be displaying.
* @param baseAngle the angle of the initial baseline.
* @param startPoint the point that is the vertex of the selected angle.
* @param endPoint the point that is the end the user is manipulating for measurement.
* @param fontsize the size to display the text label at.
*/
double fontsize)
{
// Time for the trick work of figuring out where things should go, and how.
}
// Bring it in to "title safe" for the anchor point
return where;
}
/**
* Given an angle, the arc center and edge point, draw an arc segment centered around that edge point.
*
* @param desktop the desktop that is being used.
* @param center the center point for the arc.
* @param end the point that ends at the edge of the arc segment.
* @param anchor the anchor point for displaying the text label.
* @param angle the angle of the arc segment to draw.
*/
void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom::Point const &end, Geom::Point const &anchor, double angle)
{
// Given that we have a point on the arc's edge and the angle of the arc, we need to get the two endpoints.
if (sideLen > 0.0) {
// arc start
// arc end
// from Riskus
SPCtrlCurve *curve = ControlManager::getManager().createControlCurve(desktop->getTempGroup(), p1, p2, p3, p4, CTLINE_SECONDARY);
}
}
} // namespace
{
}
MeasureTool::~MeasureTool() {
}
void MeasureTool::finish() {
this->enableGrDrag(false);
if (this->grabbed) {
}
}
//void MeasureTool::setup() {
// ToolBase* ec = this;
//
//// if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->setup) {
//// SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->setup(ec);
//// }
// ToolBase::setup();
//}
//gint MeasureTool::item_handler(SPItem* item, GdkEvent* event) {
// gint ret = FALSE;
//
//// if (SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->item_handler) {
//// ret = SP_EVENT_CONTEXT_CLASS(sp_measure_context_parent_class)->item_handler(event_context, item, event);
//// }
// ret = ToolBase::item_handler(item, event);
//
// return ret;
//}
static void calculate_intersections(SPDesktop * /*desktop*/, SPItem* item, Geom::PathVector const &lineseg, SPCurve *curve, std::vector<double> &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_KEY_PRESS: {
if (lastEnd) {
}
}
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();
}
}
double baseAngle = 0;
if (explicitBase) {
}
}
//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 over 800 points? E.g. bbox_of_measurement_line.intersects(*bbox_of_item).
// That's also how the object-snapper works, see _findCandidates() in object-snapper.cpp.
// TODO switch to a different variable name. The single letter 'l' is easy to misread.
//select elements crossed by line segment:
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);
}
}
}
}
unit_name = "px";
}
// Normal will be used for lines and text
for (std::vector<double>::iterator iter_t = intersection_times.begin(); iter_t != intersection_times.end(); iter_t++) {
}
}
// Adjust positions
{
// TODO cleanup memory, Glib::ustring, etc.:
canvas_tooltip->outline = false;
canvas_tooltip->background = true;
}
fontsize);
{
// TODO cleanup memory, Glib::ustring, etc.:
canvas_tooltip->outline = false;
canvas_tooltip->background = true;
}
{
// TODO cleanup memory, Glib::ustring, etc.:
canvas_tooltip->outline = false;
canvas_tooltip->background = true;
}
// TODO cleanup memory, Glib::ustring, etc.:
canvas_tooltip->outline = false;
canvas_tooltip->background = true;
}
// Now that text has been added, we can add lines and controls so that they go underneath
// Display the intersection indicator (i.e. the cross)
"anchor", SP_ANCHOR_CENTER,
"size", 8.0,
"stroked", TRUE,
"stroke_color", 0xff0000ff,
"mode", SP_KNOT_MODE_XOR,
"shape", SP_KNOT_SHAPE_CROSS,
NULL );
}
// Since adding goes to the bottom, do all lines last.
// draw main control line
{
if (explicitBase) {
}
}
}
SPCtrlLine *control_line = 0;
}
// call-out lines
{
}
{
}
}
// Initial point
{
"anchor", SP_ANCHOR_CENTER,
"size", 8.0,
"stroked", TRUE,
"stroke_color", 0xff0000ff,
"mode", SP_KNOT_MODE_XOR,
"shape", SP_KNOT_SHAPE_CROSS,
NULL );
}
}
break;
}
case GDK_BUTTON_RELEASE: {
//clear all temporary canvas items related to the measurement tool.
}
if (this->grabbed) {
}
xp = 0;
yp = 0;
break;
}
default:
break;
}
if (!ret) {
}
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 :