index 09fe89cff22b209d7b94c66d7551c38adc7710f5..a88688d80882fc69ffc3b7d40326c8eae33ac1fb 100644 (file)
#include "unclump.h"
#include "document.h"
#include "enums.h"
-#include "graphlayout/graphlayout.h"
+#include "graphlayout.h"
#include "inkscape.h"
#include "macros.h"
-#include "node-context.h" //For access to ShapeEditor
#include "preferences.h"
-#include "removeoverlap/removeoverlap.h"
+#include "removeoverlap.h"
#include "selection.h"
-#include "shape-editor.h" //For node align/distribute methods
#include "sp-flowtext.h"
#include "sp-item-transform.h"
#include "sp-text.h"
#include "text-editing.h"
#include "tools-switch.h"
#include "ui/icon-names.h"
+#include "ui/tool/node-tool.h"
+#include "ui/tool/multi-path-manipulator.h"
#include "util/glib-list-iterators.h"
#include "verbs.h"
#include "widgets/icon.h"
if (!_dialog.getDesktop()) return;
SPEventContext *event_context = sp_desktop_event_context(_dialog.getDesktop());
- if (!SP_IS_NODE_CONTEXT (event_context)) return ;
+ if (!INK_IS_NODE_TOOL (event_context)) return;
+ InkNodeTool *nt = INK_NODE_TOOL(event_context);
if (_distribute)
- event_context->shape_editor->distribute((Geom::Dim2)_orientation);
+ nt->_multipath->distributeNodes(_orientation);
else
- event_context->shape_editor->align((Geom::Dim2)_orientation);
+ nt->_multipath->alignNodes(_orientation);
}
};
removeOverlapXGap.set_value(0);
dialog.tooltips().set_tip(removeOverlapXGap,
_("Minimum horizontal gap (in px units) between bounding boxes"));
- /* TRANSLATORS: Horizontal gap. Only put "H:" equivalent in the translation */
- removeOverlapXGapLabel.set_label(Q_("gap|H:"));
+ //TRANSLATORS: "H:" stands for horizontal gap
+ removeOverlapXGapLabel.set_label(C_("Gap", "H:"));
removeOverlapYGap.set_digits(1);
removeOverlapYGap.set_size_request(60, -1);
dialog.tooltips().set_tip(removeOverlapYGap,
_("Minimum vertical gap (in px units) between bounding boxes"));
/* TRANSLATORS: Vertical gap */
- removeOverlapYGapLabel.set_label(_("V:"));
+ removeOverlapYGapLabel.set_label(C_("Gap", "V:"));
dialog.removeOverlap_table().attach(removeOverlapXGapLabel, column, column+1, row, row+1, Gtk::FILL, Gtk::FILL);
dialog.removeOverlap_table().attach(removeOverlapXGap, column+1, column+2, row, row+1, Gtk::FILL, Gtk::FILL);
guint row,
guint column,
AlignAndDistribute &dialog) :
- Action(id, tiptext, row, column + 4,
- dialog.graphLayout_table(), dialog.tooltips(), dialog)
+ Action(id, tiptext, row, column,
+ dialog.rearrange_table(), dialog.tooltips(), dialog)
{}
private :
}
};
+class ActionExchangePositions : public Action {
+public:
+ enum SortOrder {
+ None,
+ ZOrder,
+ Clockwise
+ };
+
+ ActionExchangePositions(Glib::ustring const &id,
+ Glib::ustring const &tiptext,
+ guint row,
+ guint column,
+ AlignAndDistribute &dialog, SortOrder order = None) :
+ Action(id, tiptext, row, column,
+ dialog.rearrange_table(), dialog.tooltips(), dialog),
+ sortOrder(order)
+ {};
+
+
+private :
+ const SortOrder sortOrder;
+ static boost::optional<Geom::Point> center;
+
+ static bool sort_compare(const SPItem * a,const SPItem * b) {
+ if (a == NULL) return false;
+ if (b == NULL) return true;
+ if (center) {
+ Geom::Point point_a = a->getCenter() - (*center);
+ Geom::Point point_b = b->getCenter() - (*center);
+ // First criteria: Sort according to the angle to the center point
+ double angle_a = atan2(double(point_a[Geom::Y]), double(point_a[Geom::X]));
+ double angle_b = atan2(double(point_b[Geom::Y]), double(point_b[Geom::X]));
+ if (angle_a != angle_b) return (angle_a < angle_b);
+ // Second criteria: Sort according to the distance the center point
+ Geom::Coord length_a = point_a.length();
+ Geom::Coord length_b = point_b.length();
+ if (length_a != length_b) return (length_a > length_b);
+ }
+ // Last criteria: Sort according to the z-coordinate
+ return (a->isSiblingOf(b));
+ }
+
+ virtual void on_button_click()
+ {
+ SPDesktop *desktop = _dialog.getDesktop();
+ if (!desktop) return;
+
+ Inkscape::Selection *selection = sp_desktop_selection(desktop);
+ if (!selection) return;
+
+ using Inkscape::Util::GSListConstIterator;
+ std::list<SPItem *> selected;
+ selected.insert<GSListConstIterator<SPItem *> >(selected.end(), selection->itemList(), NULL);
+ if (selected.empty()) return;
+
+ //Check 2 or more selected objects
+ if (selected.size() < 2) return;
+
+ // see comment in ActionAlign above
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
+ prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
+
+ // sort the list
+ if (sortOrder != None) {
+ if (sortOrder == Clockwise) {
+ center = selection->center();
+ } else { // sorting by ZOrder is outomatically done by not setting the center
+ center.reset();
+ }
+ selected.sort(ActionExchangePositions::sort_compare);
+ }
+ std::list<SPItem *>::iterator it(selected.begin());
+ Geom::Point p1 = (*it)->getCenter();
+ for (++it ;it != selected.end(); ++it)
+ {
+ Geom::Point p2 = (*it)->getCenter();
+ Geom::Point delta = p1 - p2;
+ sp_item_move_rel((*it),Geom::Translate(delta[Geom::X],delta[Geom::Y] ));
+ p1 = p2;
+ }
+ Geom::Point p2 = selected.front()->getCenter();
+ Geom::Point delta = p1 - p2;
+ sp_item_move_rel(selected.front(),Geom::Translate(delta[Geom::X],delta[Geom::Y] ));
+
+ // restore compensation setting
+ prefs->setInt("/options/clonecompensation/value", saved_compensation);
+
+ sp_document_done(sp_desktop_document(_dialog.getDesktop()), SP_VERB_DIALOG_ALIGN_DISTRIBUTE,
+ _("Exchange Positions"));
+ }
+};
+// instantiae the private static member
+boost::optional<Geom::Point> ActionExchangePositions::center;
+
class ActionUnclump : public Action {
public :
ActionUnclump(const Glib::ustring &id,
guint column,
AlignAndDistribute &dialog):
Action(id, tiptext, row, column,
- dialog.distribute_table(), dialog.tooltips(), dialog)
+ dialog.rearrange_table(), dialog.tooltips(), dialog)
{}
private :
guint column,
AlignAndDistribute &dialog):
Action(id, tiptext, row, column,
- dialog.distribute_table(), dialog.tooltips(), dialog)
+ dialog.rearrange_table(), dialog.tooltips(), dialog)
{}
private :
{
if (SP_IS_TEXT (*it) || SP_IS_FLOWTEXT (*it)) {
Inkscape::Text::Layout const *layout = te_get_layout(*it);
- Geom::Point base = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(*it);
- if (base[Geom::X] < b_min[Geom::X]) b_min[Geom::X] = base[Geom::X];
- if (base[Geom::Y] < b_min[Geom::Y]) b_min[Geom::Y] = base[Geom::Y];
- if (base[Geom::X] > b_max[Geom::X]) b_max[Geom::X] = base[Geom::X];
- if (base[Geom::Y] > b_max[Geom::Y]) b_max[Geom::Y] = base[Geom::Y];
-
- Baselines b (*it, base, _orientation);
- sorted.push_back(b);
+ boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
+ if (pt) {
+ Geom::Point base = *pt * sp_item_i2d_affine(*it);
+ if (base[Geom::X] < b_min[Geom::X]) b_min[Geom::X] = base[Geom::X];
+ if (base[Geom::Y] < b_min[Geom::Y]) b_min[Geom::Y] = base[Geom::Y];
+ if (base[Geom::X] > b_max[Geom::X]) b_max[Geom::X] = base[Geom::X];
+ if (base[Geom::Y] > b_max[Geom::Y]) b_max[Geom::Y] = base[Geom::Y];
+ Baselines b (*it, base, _orientation);
+ sorted.push_back(b);
+ }
}
}
{
if (SP_IS_TEXT (*it) || SP_IS_FLOWTEXT (*it)) {
Inkscape::Text::Layout const *layout = te_get_layout(*it);
- Geom::Point base = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(*it);
- Geom::Point t(0.0, 0.0);
- t[_orientation] = b_min[_orientation] - base[_orientation];
- sp_item_move_rel(*it, Geom::Translate(t));
- changed = true;
+ boost::optional<Geom::Point> pt = layout->baselineAnchorPoint();
+ if (pt) {
+ Geom::Point base = *pt * sp_item_i2d_affine(*it);
+ Geom::Point t(0.0, 0.0);
+ t[_orientation] = b_min[_orientation] - base[_orientation];
+ sp_item_move_rel(*it, Geom::Translate(t));
+ changed = true;
+ }
}
}
randomize_bbox(),
_alignFrame(_("Align")),
_distributeFrame(_("Distribute")),
+ _rearrangeFrame(_("Rearrange")),
_removeOverlapFrame(_("Remove overlaps")),
- _graphLayoutFrame(_("Connector network layout")),
_nodesFrame(_("Nodes")),
_alignTable(2, 6, true),
- _distributeTable(3, 6, true),
+ _distributeTable(2, 6, true),
+ _rearrangeTable(1, 5, false),
_removeOverlapTable(1, 5, false),
- _graphLayoutTable(1, 5, false),
_nodesTable(1, 4, true),
_anchorLabel(_("Relative to: ")),
_selgrpLabel(_("Treat selection as group: "))
_("Align left edges"),
0, 1);
addAlignButton(INKSCAPE_ICON_ALIGN_HORIZONTAL_CENTER,
- _("Center objects horizontally"),
+ _("Center on vertical axis"),
0, 2);
addAlignButton(INKSCAPE_ICON_ALIGN_HORIZONTAL_RIGHT,
_("Align right sides"),
_("Distribute baselines of texts vertically"),
1, 5, this->distribute_table(), Geom::Y, true);
+ // Rearrange
+ //Graph Layout
+ addGraphLayoutButton(INKSCAPE_ICON_DISTRIBUTE_GRAPH,
+ _("Nicely arrange selected connector network"),
+ 0, 0);
+ addExchangePositionsButton(INKSCAPE_ICON_EXCHANGE_POSITIONS,
+ _("Exchange positions of selected objects - selection order"),
+ 0, 1);
+ addExchangePositionsByZOrderButton(INKSCAPE_ICON_EXCHANGE_POSITIONS_ZORDER,
+ _("Exchange positions of selected objects - stacking order"),
+ 0, 2);
+ addExchangePositionsClockwiseButton(INKSCAPE_ICON_EXCHANGE_POSITIONS_CLOCKWISE,
+ _("Exchange positions of selected objects - clockwise rotate"),
+ 0, 3);
+
//Randomize & Unclump
addRandomizeButton(INKSCAPE_ICON_DISTRIBUTE_RANDOMIZE,
_("Randomize centers in both dimensions"),
- 2, 2);
+ 0, 4);
addUnclumpButton(INKSCAPE_ICON_DISTRIBUTE_UNCLUMP,
_("Unclump objects: try to equalize edge-to-edge distances"),
- 2, 4);
+ 0, 5);
//Remove overlaps
addRemoveOverlapsButton(INKSCAPE_ICON_DISTRIBUTE_REMOVE_OVERLAPS,
_("Move objects as little as possible so that their bounding boxes do not overlap"),
0, 0);
- //Graph Layout
- addGraphLayoutButton(INKSCAPE_ICON_DISTRIBUTE_GRAPH,
- _("Nicely arrange selected connector network"),
- 0, 0);
//Node Mode buttons
- addNodeButton(INKSCAPE_ICON_ALIGN_HORIZONTAL_NODES,
- _("Align selected nodes horizontally"),
- 0, Geom::X, false);
+ // NOTE: "align nodes vertically" means "move nodes vertically until they align on a common
+ // _horizontal_ line". This is analogous to what the "align-vertical-center" icon means.
+ // There is no doubt some ambiguity. For this reason the descriptions are different.
addNodeButton(INKSCAPE_ICON_ALIGN_VERTICAL_NODES,
- _("Align selected nodes vertically"),
+ _("Align selected nodes to a common horizontal line"),
+ 0, Geom::X, false);
+ addNodeButton(INKSCAPE_ICON_ALIGN_HORIZONTAL_NODES,
+ _("Align selected nodes to a common vertical line"),
1, Geom::Y, false);
addNodeButton(INKSCAPE_ICON_DISTRIBUTE_HORIZONTAL_NODE,
_("Distribute selected nodes horizontally"),
_alignFrame.add(_alignBox);
_distributeFrame.add(_distributeTable);
+ _rearrangeFrame.add(_rearrangeTable);
_removeOverlapFrame.add(_removeOverlapTable);
- _graphLayoutFrame.add(_graphLayoutTable);
_nodesFrame.add(_nodesTable);
Gtk::Box *contents = _getContents();
contents->pack_start(_alignFrame, true, true);
contents->pack_start(_distributeFrame, true, true);
+ contents->pack_start(_rearrangeFrame, true, true);
contents->pack_start(_removeOverlapFrame, true, true);
- contents->pack_start(_graphLayoutFrame, true, true);
contents->pack_start(_nodesFrame, true, true);
//Connect to the global tool change signal
((_alignFrame).*(mSel))();
((_distributeFrame).*(mSel))();
+ ((_rearrangeFrame).*(mSel))();
((_removeOverlapFrame).*(mSel))();
- ((_graphLayoutFrame).*(mSel))();
((_nodesFrame).*(mNode))();
}
@@ -1052,6 +1167,33 @@ void AlignAndDistribute::addGraphLayoutButton(const Glib::ustring &id, const Gli
);
}
+void AlignAndDistribute::addExchangePositionsButton(const Glib::ustring &id, const Glib::ustring tiptext,
+ guint row, guint col)
+{
+ _actionList.push_back(
+ new ActionExchangePositions(
+ id, tiptext, row, col, *this)
+ );
+}
+
+void AlignAndDistribute::addExchangePositionsByZOrderButton(const Glib::ustring &id, const Glib::ustring tiptext,
+ guint row, guint col)
+{
+ _actionList.push_back(
+ new ActionExchangePositions(
+ id, tiptext, row, col, *this, ActionExchangePositions::ZOrder)
+ );
+}
+
+void AlignAndDistribute::addExchangePositionsClockwiseButton(const Glib::ustring &id, const Glib::ustring tiptext,
+ guint row, guint col)
+{
+ _actionList.push_back(
+ new ActionExchangePositions(
+ id, tiptext, row, col, *this, ActionExchangePositions::Clockwise)
+ );
+}
+
void AlignAndDistribute::addUnclumpButton(const Glib::ustring &id, const Glib::ustring tiptext,
guint row, guint col)
{