Code

Merge GSoC2009 Connectors into trunk
[inkscape.git] / src / graphlayout / graphlayout.cpp
index 9285e9618cc510350104cb8f3d758c2852cf9bd9..81ea590598397ba993e4163abb4b6e456dcad680 100644 (file)
@@ -1,14 +1,15 @@
-/** \file
- * Interface between Inkscape code (SPItem) and graphlayout functions.
+/** @file
+ * @brief Interface between Inkscape code (SPItem) and graphlayout functions.
  */
 /*
-* Authors:
-*   Tim Dwyer <Tim.Dwyer@infotech.monash.edu.au>
-*
-* Copyright (C) 2005 Authors
-*
-* Released under GNU GPL.  Read the file 'COPYING' for more information.
-*/
+ * Authors:
+ *   Tim Dwyer <Tim.Dwyer@infotech.monash.edu.au>
+ *
+ * Copyright (C) 2005 Authors
+ *
+ * Released under GNU GPL.  Read the file 'COPYING' for more information.
+ */
+
 #include <iostream>
 #include <config.h>
 #include <map>
 #include "style.h"
 #include "conn-avoid-ref.h"
 #include "libavoid/connector.h"
+#include "libavoid/router.h"
 #include "libavoid/geomtypes.h"
 #include "libcola/cola.h"
 #include "libvpsc/generate-constraints.h"
-#include "prefs-utils.h"
+#include "preferences.h"
 
 using namespace std;
 using namespace cola;
@@ -65,10 +67,10 @@ struct CheckProgress : TestConvergence {
             SPItem *u=*it;
             if(!isConnector(u)) {
                 Rectangle* r=rs[nodelookup[u->id]];
-                NR::Rect const item_box(sp_item_bbox_desktop(u));
-                NR::Point const curr(item_box.midpoint());
-                NR::Point const dest(r->getCentreX(),r->getCentreY());
-                sp_item_move_rel(u, NR::translate(dest - curr));
+                Geom::Rect const item_box(sp_item_bbox_desktop(u));
+                Geom::Point const curr(item_box.midpoint());
+                Geom::Point const dest(r->getCentreX(),r->getCentreY());
+                sp_item_move_rel(u, Geom::Translate(dest - curr));
             }
         }
         */
@@ -124,10 +126,10 @@ void graphlayout(GSList const *const items) {
                ++i)
        {
                SPItem *u=*i;
-               NR::Maybe<NR::Rect> const item_box(sp_item_bbox_desktop(u));
+               Geom::OptRect const item_box(sp_item_bbox_desktop(u));
         if(item_box) {
-            NR::Point ll(item_box->min());
-            NR::Point ur(item_box->max());
+            Geom::Point ll(item_box->min());
+            Geom::Point ur(item_box->max());
             nodelookup[u->id]=rs.size();
             rs.push_back(new Rectangle(ll[0]-spacing,ur[0]+spacing,
                         ll[1]-spacing,ur[1]+spacing));
@@ -140,22 +142,13 @@ void graphlayout(GSList const *const items) {
         }
        }
 
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
        SimpleConstraints scx,scy;
-       double ideal_connector_length = prefs_get_double_attribute("tools.connector","length",100);
+       double ideal_connector_length = prefs->getDouble("/tools/connector/length", 100.0);
        double directed_edge_height_modifier = 1.0;
-       gchar const *directed_str = NULL, *overlaps_str = NULL;
-       directed_str = prefs_get_string_attribute("tools.connector",
-                       "directedlayout");
-       overlaps_str = prefs_get_string_attribute("tools.connector",
-                       "avoidoverlaplayout");
-       bool avoid_overlaps = false;
-       bool directed = false;
-    if (directed_str && !strcmp(directed_str, "true")) {
-           directed = true;
-       }
-    if (overlaps_str && !strcmp(overlaps_str, "true")) {
-           avoid_overlaps = true;
-       }
+       
+       bool directed =       prefs->getBool("/tools/connector/directedlayout");
+       bool avoid_overlaps = prefs->getBool("/tools/connector/avoidoverlaplayout");
 
        for (list<SPItem *>::iterator i(selected.begin());
                i != selected.end();
@@ -235,11 +228,11 @@ void graphlayout(GSList const *const items) {
                        map<string,unsigned>::iterator i=nodelookup.find(u->id);
                        if(i!=nodelookup.end()) {
                 Rectangle* r=rs[i->second];
-                NR::Maybe<NR::Rect> item_box(sp_item_bbox_desktop(u));
+                Geom::OptRect item_box(sp_item_bbox_desktop(u));
                 if(item_box) {
-                    NR::Point const curr(item_box->midpoint());
-                    NR::Point const dest(r->getCentreX(),r->getCentreY());
-                    sp_item_move_rel(u, NR::translate(dest - curr));
+                    Geom::Point const curr(item_box->midpoint());
+                    Geom::Point const dest(r->getCentreX(),r->getCentreY());
+                    sp_item_move_rel(u, Geom::Translate(dest - curr));
                 }
             }
                }
@@ -256,3 +249,14 @@ void graphlayout(GSList const *const items) {
 }
 // vim: set cindent 
 // vim: ts=4 sw=4 et tw=0 wm=0
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :