diff options
| author | Tim Dwyer <tgdwyer@gmail.com> | 2006-07-12 06:37:29 +0000 |
|---|---|---|
| committer | tgdwyer <tgdwyer@users.sourceforge.net> | 2006-07-12 06:37:29 +0000 |
| commit | 61b45f9df2853aa6b09df65773aa281d37b66a85 (patch) | |
| tree | 83c00e907fa90ea1f61b95c85660ce87d3c442a7 /src | |
| parent | Added layout button and ideal connector length spinbox to connector toolbar (diff) | |
| download | inkscape-61b45f9df2853aa6b09df65773aa281d37b66a85.tar.gz inkscape-61b45f9df2853aa6b09df65773aa281d37b66a85.zip | |
- 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
(bzr r1396)
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 2 | ||||
| -rw-r--r-- | src/graphlayout/graphlayout.cpp | 37 | ||||
| -rw-r--r-- | src/graphlayout/graphlayout.h | 2 | ||||
| -rw-r--r-- | src/libcola/conjugate_gradient.cpp | 4 | ||||
| -rw-r--r-- | src/ui/dialog/align-and-distribute.cpp | 2 | ||||
| -rw-r--r-- | src/widgets/toolbox.cpp | 59 |
6 files changed, 85 insertions, 21 deletions
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 <iostream> #include <config.h> +#include <map> +#include <vector> +#include <algorithm> +#include <float.h> +#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 <map> -#include <vector> -#include <algorithm> -#include <float.h> +#include "prefs-utils.h" using namespace std; using namespace cola; @@ -59,7 +60,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, 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|="<<n<<endl; //Check 2 or more selected objects if (n < 2) return; @@ -89,7 +89,6 @@ void graphlayout(GSList const *const items, double edgeLength) { NR::Point ur(item_box.max()); minX=min(ll[0],minX); minY=min(ll[1],minY); maxX=max(ur[0],maxX); maxY=max(ur[1],maxY); - cout<<"Creating node for id: "<<u->id<<endl; nodelookup[u->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: "<<iu->id<<endl; unsigned u=nodelookup[iu->id]; GSList *nlist=iu->avoidRef->getAttachedShapes(Avoid::runningFrom); list<SPItem *> 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<SPItem *>::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 <list> 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<double> 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); |
