multi-path-manipulator.cpp revision d703e5d08553a3dd5eb4f0a11040de79071bdcfb
/** @file
* Multi 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 <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"
#include "util/unordered-containers.h"
#ifdef USE_GNU_HASHES
namespace __gnu_cxx {
template<>
}
};
} // namespace __gnu_cxx
#endif // USE_GNU_HASHES
namespace Inkscape {
namespace UI {
namespace {
struct hash_nodelist_iterator
{
}
};
/** 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);
// When we encounter the mouseover node, we unset the iterator - it will be invalidated
if (i->first == preserve_pos) {
joined_pos = *i->first;
} else if (i->second == preserve_pos) {
joined_pos = *i->second;
} else {
}
// if the handles aren't degenerate, don't move them
}
}
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::joinSegments()
{
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()
{
if (_selection.empty()) {
_done("Reverse subpaths");
} else {
_done("Reverse selected subpaths");
}
}
{
_done("Move nodes");
}
{
// always show outlines for clipping paths and masks
}
}
{
}
{
}
/** @brief Set live outline update status
* When set to true, outline will be updated continuously when dragging
* or transforming nodes. Otherwise it will only update when changes are committed
* to XML. */
{
_live_outline = set;
}
/** @brief Set live object update status
* When set to true, objects will be updated continuously when dragging
* or transforming nodes. Otherwise they will only update when changes are committed
* to XML. */
{
_live_objects = set;
}
{
//for (MapType::iterator i = _mmap.begin(); i != _mmap.end(); ++i) {
// i->second->setOutlineColor(_getOutlineColor(i->first.role));
//}
}
{
}
// Single handle adjustments go here.
do {
if (!n) break;
int which = 0;
which = 1;
}
if (which != 0) break; // ambiguous
which = -1;
}
if (which == 0) break; // no handle chosen
bool handled = true;
switch (key) {
// single handle functions
// rotation
case GDK_bracketleft:
case GDK_braceleft:
break;
case GDK_bracketright:
case GDK_braceright:
break;
// adjust length
case GDK_period:
case GDK_greater:
break;
case GDK_comma:
case GDK_less:
break;
default:
handled = false;
break;
}
if (handled) return true;
} while(0);
}
case GDK_KEY_PRESS:
switch (key) {
case GDK_Insert:
case GDK_KP_Insert:
// Insert - insert nodes in the middle of selected segments
insertNodes();
return true;
case GDK_i:
case GDK_I:
// Shift+I - insert nodes (alternate keybinding for Mac keyboards
// that don't have the Insert key)
insertNodes();
return true;
}
break;
case GDK_j:
case GDK_J:
// Shift+J - join nodes
joinNodes();
return true;
}
// Alt+J - join segments
joinSegments();
return true;
}
break;
case GDK_b:
case GDK_B:
// Shift+B - break nodes
breakNodes();
return true;
}
break;
case GDK_Delete:
case GDK_KP_Delete:
case GDK_BackSpace:
// Alt+Delete - delete segments
} else {
// pass keep_shape = true when:
// a) del preserves shape, and control is not pressed
// b) ctrl+del preserves shape (del_preserves_shape is false), and control is pressed
// Hence xor
}
return true;
case GDK_c:
case GDK_C:
// Shift+C - make nodes cusp
return true;
}
break;
case GDK_s:
case GDK_S:
// Shift+S - make nodes smooth
return true;
}
break;
case GDK_a:
case GDK_A:
// Shift+A - make nodes auto-smooth
return true;
}
break;
case GDK_y:
case GDK_Y:
// Shift+Y - make nodes symmetric
return true;
}
break;
case GDK_r:
case GDK_R:
// Shift+R - reverse subpaths
return true;
}
break;
default:
break;
}
break;
case GDK_MOTION_NOTIFY:
}
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 :