Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / conn-avoid-ref.cpp
index 3e8359c579730a121735d954a1ab4010675e45f5..21ef2deab53c14bd87502c68c47648ea9c14d249 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Authors:
  *   Michael Wybrow <mjwybrow@users.sourceforge.net>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2005 Michael Wybrow
  *
@@ -28,6 +29,7 @@
 #include "libavoid/router.h"
 #include "libavoid/connector.h"
 #include "libavoid/geomtypes.h"
+#include "libavoid/shape.h"
 #include "xml/node.h"
 #include "document.h"
 #include "desktop.h"
@@ -37,7 +39,7 @@
 #include "inkscape.h"
 #include <glibmm/i18n.h>
 
-
+using Inkscape::DocumentUndo;
 
 using Avoid::Router;
 
@@ -63,8 +65,8 @@ SPAvoidRef::~SPAvoidRef()
     const bool routerInstanceExists = (item->document->router != NULL);
 
     if (shapeRef && routerInstanceExists) {
-        Router *router = shapeRef->router();
-        router->removeShape(shapeRef);
+        // Deleting the shapeRef will remove it completely from 
+        // an existing Router instance.
         delete shapeRef;
     }
     shapeRef = NULL;
@@ -194,10 +196,10 @@ void SPAvoidRef::setConnectionPointsAttrUndoable(const gchar* value, const gchar
 {
     SPDocument* doc = SP_OBJECT_DOCUMENT(item);
 
-    SP_OBJECT(item)->setAttribute( "inkscape:connection-points", value, 0 );
+    item->setAttribute( "inkscape:connection-points", value, 0 );
     item->updateRepr();
-    doc->ensure_up_to_date();
-    SPDocumentUndo::done(doc, SP_VERB_CONTEXT_CONNECTOR, action);
+    doc->ensureUpToDate();
+    DocumentUndo::done(doc, SP_VERB_CONTEXT_CONNECTOR, action);
 }
 
 void SPAvoidRef::addConnectionPoint(ConnectionPoint &cp)
@@ -294,7 +296,7 @@ void SPAvoidRef::handleSettingChange(void)
         // isn't the same as the document that this item is part of.  This
         // case can happen if a new document is loaded from the file chooser
         // or via the recent file menu.  In this case, we can end up here
-        // as a rersult of a sp_document_ensure_up_to_date performed on a
+        // as a rersult of a ensureUpToDate performed on a
         // document not yet attached to the active desktop.
         return;
     }
@@ -314,8 +316,7 @@ void SPAvoidRef::handleSettingChange(void)
             _transformed_connection = item->connectTransformed(
                     sigc::ptr_fun(&avoid_item_move));
 
-            //const char *id = SP_OBJECT_REPR(item)->attribute("id");
-            const char *id = item->getAttribute("id");
+            char const *id = item->getAttribute("id");
             g_assert(id != NULL);
 
             // Get a unique ID for the item.
@@ -330,7 +331,8 @@ void SPAvoidRef::handleSettingChange(void)
     {
         g_assert(shapeRef);
 
-        router->removeShape(shapeRef);
+        // Deleting the shapeRef will remove it completely from 
+        // an existing Router instance.
         delete shapeRef;
         shapeRef = NULL;
     }
@@ -389,8 +391,6 @@ Geom::Point SPAvoidRef::getConnectionPointPos(const int type, const int id)
     g_assert(item);
     Geom::Point pos;
     const Geom::Matrix& transform = item->i2doc_affine();
-    // TODO investigate why this was asking for the active desktop:
-    SPDesktop *desktop = inkscape_active_desktop();
 
     if ( type == ConnPointDefault )
     {
@@ -447,6 +447,12 @@ static std::vector<Geom::Point> approxCurveWithPoints(SPCurve *curve)
     {
         Geom::Path::const_iterator cit = pit->begin();
         while (cit != pit->end())
+        {
+            if (cit == pit->begin())
+            {
+                poly_points.push_back(cit->initialPoint());
+            }
+
             if (dynamic_cast<Geom::CubicBezier const*>(&*cit))
             {
                 at += seg_size;
@@ -463,6 +469,7 @@ static std::vector<Geom::Point> approxCurveWithPoints(SPCurve *curve)
                 poly_points.push_back(cit->finalPoint());
                 ++cit;
             }
+        }
         ++pit;
     }
     return poly_points;
@@ -521,7 +528,7 @@ static Avoid::Polygon avoid_item_poly(SPItem const *item)
     prev_parallel_hull_edge.origin(hull_edge.origin()+hull_edge.versor().ccw()*spacing);
     prev_parallel_hull_edge.versor(hull_edge.versor());
     int hull_size = hull.boundary.size();
-    for (int i = 0; i <= hull_size; ++i)
+    for (int i = 0; i < hull_size; ++i)
     {
         hull_edge.setBy2Points(hull[i], hull[i+1]);
         Geom::Line parallel_hull_edge;
@@ -551,8 +558,7 @@ static Avoid::Polygon avoid_item_poly(SPItem const *item)
 GSList *get_avoided_items(GSList *list, SPObject *from, SPDesktop *desktop,
         bool initialised)
 {
-    for (SPObject *child = SP_OBJECT(from)->first_child() ;
-            child != NULL; child = SP_OBJECT_NEXT(child) ) {
+    for (SPObject *child = from->firstChild() ; child != NULL; child = child->next ) {
         if (SP_IS_ITEM(child) &&
             !desktop->isLayer(SP_ITEM(child)) &&
             !SP_ITEM(child)->isLocked() &&
@@ -590,8 +596,8 @@ void init_avoided_shape_geometry(SPDesktop *desktop)
     // Don't count this as changes to the document,
     // it is basically just late initialisation.
     SPDocument *document = sp_desktop_document(desktop);
-    bool saved = SPDocumentUndo::get_undo_sensitive(document);
-       SPDocumentUndo::set_undo_sensitive(document, false);
+    bool saved = DocumentUndo::getUndoSensitive(document);
+    DocumentUndo::setUndoSensitive(document, false);
 
     bool initialised = false;
     GSList *items = get_avoided_items(NULL, desktop->currentRoot(), desktop,
@@ -605,7 +611,7 @@ void init_avoided_shape_geometry(SPDesktop *desktop)
     if (items) {
         g_slist_free(items);
     }
-       SPDocumentUndo::set_undo_sensitive(document, saved);
+    DocumentUndo::setUndoSensitive(document, saved);
 }