Code

Update LPE helper paths "live" on changes
authorcilix42 <cilix42@users.sourceforge.net>
Wed, 18 Jun 2008 22:30:22 +0000 (22:30 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Wed, 18 Jun 2008 22:30:22 +0000 (22:30 +0000)
src/shape-editor.cpp
src/sp-lpe-item.cpp
src/sp-lpe-item.h

index d5712525aea92a5e52d9d155b97e2d59f70b84fb..4b71184e4c5843007107af130e1d7b3888a5d569 100644 (file)
@@ -198,7 +198,7 @@ void ShapeEditor::set_item(SPItem *item) {
                 // or the LPE is invisible or it doesn't provide a knotholder itself
                 this->nodepath = sp_nodepath_new(desktop, item,
                                                  (prefs_get_int_attribute("tools.nodes", "show_handles", 1) != 0));
-            } else if (lpe && lpe->isVisible() && lpe->showOrigPath()) {
+            } else if (lpe && lpe->isVisible()) {
                 sp_lpe_item_add_temporary_canvasitems(lpeitem, desktop);
             }
         }
index 4c2ca3857f6bc28b920a68799ebc85c9f3728328..2ba1c86c216b6c453c9590e94fa65568bfb2815d 100644 (file)
@@ -118,6 +118,9 @@ sp_lpe_item_init(SPLPEItem *lpeitem)
     lpeitem->current_path_effect = NULL;
 
     new (&lpeitem->lpe_modified_connection) sigc::connection();
+
+    lpeitem->adding_helperpaths = false;
+    lpeitem->removing_helperpaths = false;
 }
 
 static void
@@ -345,6 +348,13 @@ sp_lpe_item_update_patheffect (SPLPEItem *lpeitem, bool wholetree, bool write)
         top = lpeitem;
     }
 
+    // TODO: ditch inkscape_active_desktop()
+    SPDesktop *desktop = inkscape_active_desktop();
+    if (desktop) {
+        sp_lpe_item_remove_temporary_canvasitems(lpeitem, desktop);
+        sp_lpe_item_add_temporary_canvasitems(lpeitem, desktop);
+    }
+
     if (SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (top))->update_patheffect) {
         SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (top))->update_patheffect (top, write);
     }
@@ -711,20 +721,38 @@ bool sp_lpe_item_path_effects_enabled(SPLPEItem *lpeitem)
 void
 sp_lpe_item_add_temporary_canvasitems(SPLPEItem *lpeitem, SPDesktop *desktop)
 {
+    if (lpeitem->adding_helperpaths) {
+        return;
+    }
+    lpeitem->adding_helperpaths = true;
+    // FIXME: for some reason it seems that we must create the variable lpe AFTER checking
+    //        for adding_helperpaths == true; otherwise we get a crash on startup. why??
     Inkscape::LivePathEffect::Effect *lpe = sp_lpe_item_get_current_lpe(lpeitem);
     if (lpe) {
+        // TODO: can we just update the tempitem's SPCurve instead of recreating it each time?
         lpe->addHelperPaths(lpeitem, desktop);
     }
+    lpeitem->adding_helperpaths = false;
 }
 
 void
 sp_lpe_item_remove_temporary_canvasitems(SPLPEItem *lpeitem, SPDesktop *desktop)
 {
+    g_return_if_fail(lpeitem);
+    g_return_if_fail(desktop);
+
+    if (lpeitem->removing_helperpaths) {
+        return;
+    }
+    lpeitem->removing_helperpaths = true;
+
     // destroy all temporary canvasitems created by LPEs
     std::vector<Inkscape::Display::TemporaryItem*>::iterator i;
     for (i = lpeitem->lpe_helperpaths.begin(); i != lpeitem->lpe_helperpaths.end(); ++i) {
         desktop->remove_temporary_canvasitem(*i);
     }
+
+    lpeitem->removing_helperpaths = false;
 }
 
 /*
index 7691ce9803525898d5e177cfa5ae6eefb3acfdae..54642f27b17a657c7f321bb2437d2b20c8f77bd8 100644 (file)
@@ -42,6 +42,9 @@ struct SPLPEItem : public SPItem {
     Inkscape::LivePathEffect::LPEObjectReference* current_path_effect;
     std::vector<Inkscape::Display::TemporaryItem*> lpe_helperpaths;
 
+    bool adding_helperpaths;
+    bool removing_helperpaths;
+
     sigc::connection lpe_modified_connection;
 };