multi-path-manipulator.cpp revision 70d31ae8a7a27e57cfcdc921ea0d2f47c92442a4
/** @file
* Path manipulator - implementation
*/
/* Authors:
* Krzysztof KosiĆski <tweenk.pl@gmail.com>
*
* Copyright (C) 2009 Authors
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <tr1/unordered_set>
#include <boost/shared_ptr.hpp>
#include <glib.h>
#include "desktop.h"
#include "desktop-handles.h"
#include "document.h"
#include "live_effects/lpeobject.h"
#include "message-stack.h"
#include "preferences.h"
#include "sp-path.h"
#include "ui/tool/control-point-selection.h"
#include "ui/tool/event-utils.h"
#include "ui/tool/multi-path-manipulator.h"
#include "ui/tool/path-manipulator.h"
namespace Inkscape {
namespace UI {
namespace {
/** Find pairs of selected endnodes suitable for joining. */
{
// find all endnodes in selection
if (!node) continue;
}
// Below we find the closest pairs. The algorithm is O(N^3).
// We can go down to O(N^2 log N) by using O(N^2) memory, by putting all pairs
// with their distances in a multimap (not worth it IMO).
}
}
}
}
}
/** After this function, first should be at the end of path and second at the beginnning.
* @returns True if the nodes are in the same subpath */
{
return true;
}
} else { // second is end
}
} else { // first is end
// do nothing
} else { // second is end
}
}
return false;
}
} // anonymous namespace
, _path_data(data)
{
}
{
}
/** Remove empty manipulators. */
void MultiPathManipulator::cleanup()
{
else ++i;
}
}
/** @brief Change the set of items to edit.
*
* This method attempts to preserve as much of the state as possible. */
{
// iterate over currently edited items, modifying / removing them as necessary
// This item is no longer supposed to be edited - remove its manipulator
} else {
// if the shape record differs, replace the key only and modify other values
{
//hold->setOutlineColor(_getOutlineColor(sr_new.role));
}
}
++i;
}
}
// add newly selected items
ShapeRecord const &r = *i;
// always show outlines for clips and masks
}
}
void MultiPathManipulator::selectSubpaths()
{
if (_selection.empty()) {
} else {
}
}
{
}
{
}
{
if (_selection.empty()) return;
}
_done(_("Change node type"));
}
{
if (_selection.empty()) return;
if (type == SEGMENT_STRAIGHT) {
_done(_("Straighten segments"));
} else {
_done(_("Make segments curves"));
}
}
void MultiPathManipulator::insertNodes()
{
_done(_("Add nodes"));
}
void MultiPathManipulator::joinNodes()
{
// Node join has two parts. In the first one we join two subpaths by fusing endpoints
// into one. In the second we fuse nodes in each subpath.
if (mouseover_node) {
}
bool same_path = prepare_join(*i);
bool mouseover = true;
if (i->first == preserve_pos) {
joined_pos = *i->first;
} else if (i->second == preserve_pos) {
joined_pos = *i->second;
} else {
mouseover = false;
}
// if the handles aren't degenerate, don't move them
}
}
if (mouseover) {
// Second node could be mouseovered, but it will be deleted, so we must change
// the preserve_pos iterator to the first node.
preserve_pos = i->first;
}
if (same_path) {
} else {
}
}
// Second part replaces contiguous selections of nodes with single nodes
_doneWithCleanup(_("Join nodes"));
}
void MultiPathManipulator::breakNodes()
{
if (_selection.empty()) return;
_done(_("Break nodes"));
}
{
if (_selection.empty()) return;
_doneWithCleanup(_("Delete nodes"));
}
/** Join selected endpoints to create segments. */
void MultiPathManipulator::joinSegment()
{
_("There must be at least 2 endnodes in selection"));
return;
}
bool same_path = prepare_join(*i);
if (same_path) {
} else {
}
}
_doneWithCleanup("Join segments");
}
void MultiPathManipulator::deleteSegments()
{
if (_selection.empty()) return;
_doneWithCleanup("Delete segments");
}
{
_selection.align(d);
if (d == Geom::X) {
_done("Align nodes to a horizontal line");
} else {
_done("Align nodes to a vertical line");
}
}
{
_selection.distribute(d);
if (d == Geom::X) {
_done("Distrubute nodes horizontally");
} else {
_done("Distribute nodes vertically");
}
}
void MultiPathManipulator::reverseSubpaths()
{
_done("Reverse selected subpaths");
}
{
_done("Move nodes");
}
{
// always show outlines for clipping paths and masks
}
}
{
}
{
}
{
//for (MapType::iterator i = _mmap.begin(); i != _mmap.end(); ++i) {
// i->second->setOutlineColor(_getOutlineColor(i->first.role));
//}
}
{
case GDK_KEY_PRESS:
case GDK_Insert:
case GDK_KP_Insert:
insertNodes();
return true;
case GDK_i:
case GDK_I:
insertNodes();
return true;
}
break;
case GDK_j:
case GDK_J:
joinNodes();
return true;
}
joinSegment();
return true;
}
break;
case GDK_b:
case GDK_B:
breakNodes();
return true;
}
break;
case GDK_Delete:
case GDK_KP_Delete:
case GDK_BackSpace:
} else {
}
return true;
case GDK_c:
case GDK_C:
return true;
}
break;
case GDK_s:
case GDK_S:
return true;
}
break;
case GDK_a:
case GDK_A:
return true;
}
break;
case GDK_y:
case GDK_Y:
return true;
}
break;
case GDK_r:
case GDK_R:
break;
}
break;
default:
break;
}
break;
default: break;
}
}
return false;
}
/** Commit changes to XML and add undo stack entry based on the action that was done. Invoked
* by sub-manipulators, for example TransformHandleSet and ControlPointSelection. */
{
switch(cps) {
case COMMIT_MOUSE_MOVE:
reason = _("Move nodes");
break;
case COMMIT_KEYBOARD_MOVE_X:
reason = _("Move nodes horizontally");
key = "node:move:x";
break;
case COMMIT_KEYBOARD_MOVE_Y:
reason = _("Move nodes vertically");
key = "node:move:y";
break;
case COMMIT_MOUSE_ROTATE:
reason = _("Rotate nodes");
break;
case COMMIT_KEYBOARD_ROTATE:
reason = _("Rotate nodes");
key = "node:rotate";
break;
reason = _("Scale nodes uniformly");
break;
case COMMIT_MOUSE_SCALE:
reason = _("Scale nodes");
break;
reason = _("Scale nodes uniformly");
key = "node:scale:uniform";
break;
case COMMIT_KEYBOARD_SCALE_X:
reason = _("Scale nodes horizontally");
key = "node:scale:x";
break;
case COMMIT_KEYBOARD_SCALE_Y:
reason = _("Scale nodes vertically");
key = "node:scale:y";
break;
case COMMIT_FLIP_X:
reason = _("Flip nodes horizontally");
break;
case COMMIT_FLIP_Y:
reason = _("Flip nodes vertically");
break;
default: return;
}
if (key) {
} else {
}
}
/** Commits changes to XML and adds undo stack entry. */
}
/** Commits changes to XML, adds undo stack entry and removes empty manipulators. */
cleanup();
}
/** Get an outline color based on the shape's role (normal, mask, LPE parameter, etc.). */
{
switch(role) {
case SHAPE_ROLE_CLIPPING_PATH:
case SHAPE_ROLE_MASK:
case SHAPE_ROLE_LPE_PARAM:
case SHAPE_ROLE_NORMAL:
default:
}
}
} // namespace UI
} // namespace Inkscape
/*
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:encoding=utf-8:textwidth=99 :