Code

Added layout button and ideal connector length spinbox to connector toolbar
authortgdwyer <tgdwyer@users.sourceforge.net>
Wed, 12 Jul 2006 02:26:13 +0000 (02:26 +0000)
committertgdwyer <tgdwyer@users.sourceforge.net>
Wed, 12 Jul 2006 02:26:13 +0000 (02:26 +0000)
src/graphlayout/graphlayout.cpp
src/graphlayout/graphlayout.h
src/ui/dialog/align-and-distribute.cpp
src/widgets/toolbox.cpp

index 42b867a335d233dff9bb2f8e38e7890f4369b89e..69d26120d29ff703ed07238181461513753eb435 100644 (file)
@@ -59,7 +59,7 @@ void filterConnectors(GSList const *const items, list<SPItem *> &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<SPItem *>::iterator it(selected.begin());
index 40090ef6b54ad8b3ced046f827cdebec765e51cb..2e8de2ddd18a54671ceb7e329221a5f95f6e6ee1 100644 (file)
@@ -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 <list>
index a7b2aa991ecdc59b9656700fea347e16757c00dd..dda9cad5f0a29978b17e3c21354c213d47093d73 100644 (file)
@@ -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);
index 6862794b33034a292283e46ff6514188c1050a55..4fa2d6044f87c95e1488b754e7de03fa7df01c59 100644 (file)
@@ -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);