From c787248292420aeb9b05e2e4852df8291904cdee Mon Sep 17 00:00:00 2001 From: tgdwyer Date: Wed, 12 Jul 2006 06:37:29 +0000 Subject: [PATCH] - added toggle buttons for directed layout (doesn't do anything yet) and overlap avoiding layout to connector toolbar - added icon for directed layout toggle button - removed old ref to remove_rectangle_overlaps-test from src/Makefile.am --- share/icons/icons.svg | 91 +++++++++++++++++++++++++- src/Makefile.am | 2 - src/graphlayout/graphlayout.cpp | 37 +++++++---- src/graphlayout/graphlayout.h | 2 +- src/libcola/conjugate_gradient.cpp | 4 +- src/ui/dialog/align-and-distribute.cpp | 2 +- src/widgets/toolbox.cpp | 59 +++++++++++++++-- 7 files changed, 174 insertions(+), 23 deletions(-) diff --git a/share/icons/icons.svg b/share/icons/icons.svg index 2b7c4ff34..922b6ba00 100644 --- a/share/icons/icons.svg +++ b/share/icons/icons.svg @@ -14,9 +14,35 @@ width="1000.0000pt" sodipodi:version="0.32" id="svg1" - sodipodi:docbase="/usr/local/src/inkscape/share/icons"> + sodipodi:docbase="/home/dwyer/devel/inkscape/share/icons"> + + + + + + + transform="translate(-48,41)"> id="path11171" /> + + + + + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am index 6358d35dd..f69bb9bf1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -182,7 +182,6 @@ TESTS = \ libnr/nr-translate-test$(EXEEXT) \ libnr/nr-types-test$(EXEEXT) \ libnr/test-nr$(EXEEXT) \ - removeoverlap/remove_rectangle_overlap-test$(EXEEXT) \ svg/test-svg$(EXEEXT) \ util/list-container-test$(EXEEXT) \ xml/test-xml$(EXEEXT) \ @@ -210,7 +209,6 @@ check_PROGRAMS = \ libnr/nr-translate-test \ libnr/nr-types-test \ libnr/test-nr \ - removeoverlap/remove_rectangle_overlap-test \ svg/test-svg \ util/list-container-test \ xml/test-xml \ diff --git a/src/graphlayout/graphlayout.cpp b/src/graphlayout/graphlayout.cpp index 69d26120d..ac2d5429f 100644 --- a/src/graphlayout/graphlayout.cpp +++ b/src/graphlayout/graphlayout.cpp @@ -9,11 +9,15 @@ * * Released under GNU GPL. Read the file 'COPYING' for more information. */ -#include "util/glib-list-iterators.h" -#include "graphlayout/graphlayout.h" #include #include +#include +#include +#include +#include +#include "util/glib-list-iterators.h" +#include "graphlayout/graphlayout.h" #include "sp-path.h" #include "sp-item.h" #include "sp-item-transform.h" @@ -23,10 +27,7 @@ #include "libavoid/geomtypes.h" #include "libcola/cola.h" #include "libvpsc/generate-constraints.h" -#include -#include -#include -#include +#include "prefs-utils.h" using namespace std; using namespace cola; @@ -59,7 +60,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, double edgeLength) { +void graphlayout(GSList const *const items) { if(!items) { return; } @@ -70,7 +71,6 @@ void graphlayout(GSList const *const items, double edgeLength) { if (selected.empty()) return; const unsigned n=selected.size(); - cout<<"|V|="<id<id]=rs.size(); rs.push_back(new Rectangle(ll[0],ur[0],ll[1],ur[1])); } @@ -100,7 +99,6 @@ void graphlayout(GSList const *const items, double edgeLength) { ++i) { SPItem *iu=*i; - cout<<"Getting neighbours for id: "<id<id]; GSList *nlist=iu->avoidRef->getAttachedShapes(Avoid::runningFrom); list neighbours; @@ -124,7 +122,24 @@ void graphlayout(GSList const *const items, double edgeLength) { double eweights[E]; fill(eweights,eweights+E,1); - ConstrainedMajorizationLayout alg(rs,es,eweights,edgeLength); + ConstrainedMajorizationLayout alg(rs,es,eweights, + prefs_get_double_attribute("tools.connector","length",100)); + gchar const *directed = NULL, *overlaps = NULL; + directed = prefs_get_string_attribute("tools.connector", + "directedlayout"); + overlaps = prefs_get_string_attribute("tools.connector", + "avoidoverlaplayout"); + bool avoid_overlaps = false; + if (directed && !strcmp(directed, "true")) { + cout << "Directed layout requested, but not yet implemented\n"; + cout << " because we haven't coded cyclic removal alg...\n"; + } + if (overlaps && !strcmp(overlaps, "true")) { + cout << "Avoid overlaps requested.\n"; + avoid_overlaps = true; + } + alg.setupConstraints(NULL,NULL,avoid_overlaps, + NULL,NULL,NULL,NULL,NULL,NULL); alg.run(); for (list::iterator it(selected.begin()); diff --git a/src/graphlayout/graphlayout.h b/src/graphlayout/graphlayout.h index 2e8de2ddd..40090ef6b 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, double edgeLength); +void graphlayout(_GSList const *const items); class SPItem; bool isConnector(SPItem const *const item); #include diff --git a/src/libcola/conjugate_gradient.cpp b/src/libcola/conjugate_gradient.cpp index 5dfb4363d..ed8ffbfed 100644 --- a/src/libcola/conjugate_gradient.cpp +++ b/src/libcola/conjugate_gradient.cpp @@ -97,8 +97,8 @@ conjugate_gradient(valarray const &A, r -= alpha_k*Ap; r_r = r_r_new; } - printf("njh: %d iters, Linfty = %g L2 = %g\n", k, - std::max(-r.min(), r.max()), sqrt(r_r)); + //printf("njh: %d iters, Linfty = %g L2 = %g\n", k, + //std::max(-r.min(), r.max()), sqrt(r_r)); // x is solution } /* diff --git a/src/ui/dialog/align-and-distribute.cpp b/src/ui/dialog/align-and-distribute.cpp index dda9cad5f..a7b2aa991 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(),100); + graphlayout(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()); // 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 4fa2d6044..b0ab387f0 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -3890,19 +3890,41 @@ static void sp_connector_graph_layout(void) { if (!SP_ACTIVE_DESKTOP) return; - // see comment in ActionAlign above + // hack for clones, see comment in align-and-distribute.cpp 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)); + graphlayout(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()); - // 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 +sp_directed_graph_layout_toggled(GtkWidget *widget, GtkObject *tbl) +{ + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { + prefs_set_string_attribute("tools.connector", "directedlayout", + "true"); + } else { + prefs_set_string_attribute("tools.connector", "directedlayout", + "false"); + } +} +static void +sp_nooverlaps_graph_layout_toggled(GtkWidget *widget, GtkObject *tbl) +{ + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) { + prefs_set_string_attribute("tools.connector", "avoidoverlaplayout", + "true"); + } else { + prefs_set_string_attribute("tools.connector", "avoidoverlaplayout", + "false"); + } +} + + static void connector_length_changed(GtkAdjustment *adj, GtkWidget *tbl) { prefs_set_double_attribute("tools.connector", "length", adj->value); @@ -3990,6 +4012,35 @@ sp_connector_toolbox_new(SPDesktop *desktop) gtk_box_pack_start(GTK_BOX(tbl), connector_length, FALSE, FALSE, AUX_SPACING); } + gchar const *tbuttonstate; + // Directed edges toggle button + { + GtkWidget *tbutton = gtk_toggle_button_new (); + gtk_button_set_relief (GTK_BUTTON (tbutton), GTK_RELIEF_NONE); + gtk_container_add (GTK_CONTAINER (tbutton), sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, "directed_graph")); + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (tbutton), FALSE); + gtk_tooltips_set_tip(tt, tbutton, _("Make connectors point downwards"), NULL); + + gtk_box_pack_start (GTK_BOX (tbl), tbutton, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(tbutton), "toggled", GTK_SIGNAL_FUNC(sp_directed_graph_layout_toggled), tbl); + tbuttonstate = prefs_get_string_attribute("tools.connector", "directedlayout"); + gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(tbutton), + (tbuttonstate && !strcmp(tbuttonstate, "true"))?TRUE:FALSE ); + } + // Avoid overlaps toggle button + { + GtkWidget *tbutton = gtk_toggle_button_new (); + gtk_button_set_relief (GTK_BUTTON (tbutton), GTK_RELIEF_NONE); + gtk_container_add (GTK_CONTAINER (tbutton), sp_icon_new (Inkscape::ICON_SIZE_SMALL_TOOLBAR, "remove_overlaps")); + gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (tbutton), FALSE); + gtk_tooltips_set_tip(tt, tbutton, _("Do not allow overlapping shapes"), NULL); + + gtk_box_pack_start (GTK_BOX (tbl), tbutton, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(tbutton), "toggled", GTK_SIGNAL_FUNC(sp_nooverlaps_graph_layout_toggled), tbl); + tbuttonstate = prefs_get_string_attribute("tools.connector", "avoidoverlaplayout"); + gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(tbutton), + (tbuttonstate && !strcmp(tbuttonstate, "true"))?TRUE:FALSE ); + } gtk_widget_show_all(tbl); sp_set_font_size_smaller (tbl); -- 2.30.2