From a7f9305a82b43cf9bd356c6e19d43e73409d178c Mon Sep 17 00:00:00 2001 From: tgdwyer Date: Wed, 12 Jul 2006 02:26:13 +0000 Subject: [PATCH] Added layout button and ideal connector length spinbox to connector toolbar --- src/graphlayout/graphlayout.cpp | 4 +-- src/graphlayout/graphlayout.h | 2 +- src/ui/dialog/align-and-distribute.cpp | 2 +- src/widgets/toolbox.cpp | 39 ++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/graphlayout/graphlayout.cpp b/src/graphlayout/graphlayout.cpp index 42b867a33..69d26120d 100644 --- a/src/graphlayout/graphlayout.cpp +++ b/src/graphlayout/graphlayout.cpp @@ -59,7 +59,7 @@ void filterConnectors(GSList const *const items, list &filtered) { * connectors between them, and uses graph layout techniques to find * a nice layout */ -void graphlayout(GSList const *const items) { +void graphlayout(GSList const *const items, double edgeLength) { if(!items) { return; } @@ -124,7 +124,7 @@ void graphlayout(GSList const *const items) { double eweights[E]; fill(eweights,eweights+E,1); - ConstrainedMajorizationLayout alg(rs,es,eweights,width/n); + ConstrainedMajorizationLayout alg(rs,es,eweights,edgeLength); alg.run(); for (list::iterator it(selected.begin()); diff --git a/src/graphlayout/graphlayout.h b/src/graphlayout/graphlayout.h index 40090ef6b..2e8de2ddd 100644 --- a/src/graphlayout/graphlayout.h +++ b/src/graphlayout/graphlayout.h @@ -13,7 +13,7 @@ #define SEEN_GRAPHLAYOUT_H struct _GSList; -void graphlayout(_GSList const *const items); +void graphlayout(_GSList const *const items, double edgeLength); class SPItem; bool isConnector(SPItem const *const item); #include diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index a7b2aa991..dda9cad5f 100644 --- a/src/ui/dialog/align-and-distribute.cpp +++ b/src/ui/dialog/align-and-distribute.cpp @@ -511,7 +511,7 @@ private : int saved_compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED); prefs_set_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED); - graphlayout(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()); + graphlayout(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(),100); // restore compensation setting prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation); diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 6862794b3..4fa2d6044 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -76,6 +76,7 @@ #include "../prefs-utils.h" #include "../inkscape-stock.h" #include "icon.h" +#include "graphlayout/graphlayout.h" #include "mod360.h" @@ -3841,6 +3842,7 @@ static void sp_connector_path_set_ignore(void) } + static void connector_spacing_changed(GtkAdjustment *adj, GtkWidget *tbl) { // quit if run by the _changed callbacks @@ -3884,6 +3886,28 @@ static void connector_spacing_changed(GtkAdjustment *adj, GtkWidget *tbl) spinbutton_defocus(GTK_OBJECT(tbl)); } +static void sp_connector_graph_layout(void) +{ + if (!SP_ACTIVE_DESKTOP) return; + + // see comment in ActionAlign above + int saved_compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED); + prefs_set_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED); + + graphlayout(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(), + prefs_get_double_attribute("tools.connector","length",100)); + + // restore compensation setting + prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation); + + sp_document_done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, /* TODO: annotate */ "toolbox.cpp:129"); +} + +static void connector_length_changed(GtkAdjustment *adj, GtkWidget *tbl) +{ + prefs_set_double_attribute("tools.connector", "length", adj->value); + spinbutton_defocus(GTK_OBJECT(tbl)); +} static void connector_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name, gchar const *old_value, gchar const *new_value, @@ -3951,6 +3975,21 @@ sp_connector_toolbox_new(SPDesktop *desktop) gtk_box_pack_start(GTK_BOX(tbl), object_spacing, FALSE, FALSE, AUX_SPACING); } + // Graph (connector network) layout + sp_toolbox_button_new(tbl, Inkscape::ICON_SIZE_SMALL_TOOLBAR, + "graph_layout", GTK_SIGNAL_FUNC(sp_connector_graph_layout), + tt, _("Nicely arrange selected connector network")); + // Default connector length spinbox + { + GtkWidget *connector_length = sp_tb_spinbutton(_("Length:"), + _("Ideal length for connectors when layout is applied"), + "tools.connector", "length", 100, NULL, tbl, TRUE, + "inkscape:connector-length", 10, 1000, 10.0, 100.0, + connector_length_changed, 1, 0); + + gtk_box_pack_start(GTK_BOX(tbl), connector_length, FALSE, FALSE, + AUX_SPACING); + } gtk_widget_show_all(tbl); sp_set_font_size_smaller (tbl); -- 2.30.2