node.h revision 4aeaa765c1779bb282e9cb7b8ad14cc1fae248ef
/** @file
* Editable node and associated data structures.
*/
/* Authors:
* Krzysztof KosiĆski <tweenk.pl@gmail.com>
* Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2009 Authors
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifndef SEEN_UI_TOOL_NODE_H
#define SEEN_UI_TOOL_NODE_H
#include <iterator>
#include <iosfwd>
#include <stdexcept>
#include <cstddef>
#if __cplusplus >= 201103L
#include <functional>
#else
#include <tr1/functional>
#endif
#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>
#include "ui/tool/selectable-control-point.h"
#include "snapped-point.h"
#include "ui/tool/node-types.h"
struct SPCtrlLine;
}
}
#if __cplusplus < 201103L
}
}
#endif
/*
template <typename T>
struct ListMember {
T *next;
T *prev;
};
struct SubpathMember : public ListMember<NodeListMember> {
Subpath *list;
};
struct SubpathListMember : public ListMember<SubpathListMember> {
SubpathList *list;
};
*/
struct ListNode {
};
struct NodeSharedData {
};
inline double length() const;
bool isDegenerate() const { return _degenerate; } // True if the handle is retracted, i.e. has zero length.
virtual void setVisible(bool);
void retract();
virtual void handle_2button_press();
virtual bool _hasDragTips() const { return true; }
inline PathManipulator &_pm();
// so a naked pointer is OK and allows setting it during Node's construction
bool _degenerate; // True if the handle is retracted, i.e. has zero length. This is used often internally so it makes sense to cache this
/**
* Control point of a cubic Bezier curve in a path.
*
* Handle keeps the node type invariant only for the opposite handle of the same node.
* Keeping the invariant on node moves is left to the %Node class.
*/
static double _saved_length;
static bool _drag_out;
static ColorSet _handle_colors;
};
/**
* Curve endpoint in an editable path.
*
* The method move() keeps node type invariants during translations.
*/
/**
* Sets the node type and optionally restores the invariants associated with the given type.
* @param type The type to set.
* @param update_handles Whether to restore invariants associated with the given type.
* Passing false is useful e.g. wen initially creating the path,
* and when making cusp nodes during some node algorithms.
* Pass true when used in response to an UI node type button.
*/
void showHandles(bool v);
void updateHandles();
/**
* Pick the best type for this node, based on the position of its handles.
* This is what assigns types to nodes created using the pen tool.
*/
void pickBestType(); // automatically determine the type from handle positions
bool isEndNode() const;
//strength value for each node
double bsplineWeight;
/**
* Gets the handle that faces the given adjacent node.
* Will abort with error if the given node is not adjacent.
*/
/**
* Gets the node in the direction of the given handle.
* Will abort with error if the handle doesn't belong to this node.
*/
/**
* Gets the handle that goes in the direction opposite to the given adjacent node.
* Will abort with error if the given node is not adjacent.
*/
/**
* Gets the node in the direction opposite to the given handle.
* Will abort with error if the handle doesn't belong to this node.
*/
/**
* Move the node to the bottom of its canvas group.
* Useful for node break, to ensure that the selected nodes are above the unselected ones.
*/
void sink();
static NodeType parse_nodetype(char x);
// temporarily public
virtual bool _hasDragTips() const { return true; }
void _updateAutoHandles();
/**
* Select or deselect a node in this node's subpath based on its path distance from this node.
* @param dir If negative, shrink selection by one node; if positive, grow by one node.
*/
void _linearGrow(int dir);
inline PathManipulator &_pm();
/** Determine whether two nodes are joined by a linear segment. */
// Handles are always present, but are not visible if they coincide with the node
// (are degenerate). A segment that has both handles degenerate is always treated
// as a line segment
bool _handles_shown;
static ColorSet node_colors;
};
/// Iterator for editable nodes
/** Use this class for all operations that require some knowledge about the node's
* neighbors. It is a bidirectional iterator.
*
* Because paths can be cyclic, node iterators have two different ways to
* increment and decrement them. When using ++/--, the end iterator will eventually
* be returned. Whent using advance()/retreat(), the end iterator will only be returned
* when the path is open. If it's closed, calling advance() will cycle indefinitely.
* This is particularly useful for cases where the adjacency of nodes is more important
* than their sequence order.
*
* When @a i is a node iterator, then:
* - <code>++i</code> moves the iterator to the next node in sequence order;
* - <code>--i</code> moves the iterator to the previous node in sequence order;
* - <code>i.next()</code> returns the next node with wrap-around;
* - <code>i.prev()</code> returns the previous node with wrap-around;
* - <code>i.advance()</code> moves the iterator to the next node with wrap-around;
* - <code>i.retreat()</code> moves the iterator to the previous node with wrap-around.
*
* next() and prev() do not change their iterator. They can return the end iterator
* if the path is open.
*
* Unlike most other iterators, you can check whether you've reached the end of the list
* without having access to the iterator's container.
* Simply use <code>if (i) { ...</code>
* */
N *, N &>
{
typedef NodeIterator self;
: _node(0)
{}
// default copy, default assign
return *this;
}
return *this;
}
bool operator==(self const &other) const { if(&other){return _node == other._node;} else{return false;} }
inline operator bool() const; // define after NodeList
/// Get a pointer to the underlying node. Equivalent to <code>&*i</code>.
/// @see get_pointer()
r.advance();
return r;
}
r.retreat();
return r;
}
NodeIterator(ListNode const *n)
{}
};
typedef Node const &const_reference;
typedef Node const *const_pointer;
typedef Node value_type;
// TODO Lame. Make this private and make SubpathList a factory
/**
* An editable list of nodes representing a subpath.
*
* It can optionally be cyclic to represent a closed path.
* The list has iterators that act like plain node iterators, but can also be used
* to obtain shared pointers to nodes.
*/
~NodeList();
// iterators
// size
bool empty();
// extra node-specific methods
bool closed();
/**
* A subpath is degenerate if it has no segments - either one node in an open path
* or no nodes in a closed path.
*/
bool degenerate();
}
// list operations
/** insert a node before pos. */
}
void reverse();
void shift(int n);
void clear();
return ret;
}
// member access - undefined results when the list is empty
// HACK remove this subpath from its path. This will be removed later.
void kill();
// no copy or assign
bool _closed;
};
/**
* List of node lists. Represents an editable path.
* Editable path composed of one or more subpaths.
*/
};
// define inline Handle funcs after definition of Node
}
}
return relativePos().length();
}
}
}
// definitions for node iterator
NodeIterator<N>::operator bool() const {
}
++(*this);
return *this;
}
--(*this);
return *this;
}
} // namespace UI
} // namespace Inkscape
#endif
/*
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:fileencoding=utf-8:textwidth=99 :