Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / live_effects / effect.cpp
index d7613fb326dadf6503e9f77101fba6e67879720f..3ea57de23f3f3110134db2e8654e8dd82d19c7ca 100644 (file)
@@ -1,13 +1,18 @@
-#define INKSCAPE_LIVEPATHEFFECT_CPP
-
 /*
  * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
+ *   Abhishek Sharma
  *
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
 
+//#define LPE_ENABLE_TEST_EFFECTS
+
 #include "live_effects/effect.h"
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "xml/node-event-vector.h"
 #include "sp-object.h"
 #include "attributes.h"
@@ -22,8 +27,8 @@
 #include "tools-switch.h"
 #include "message-stack.h"
 #include "desktop.h"
-#include "nodepath.h"
-
+#include "knotholder.h"
+#include "sp-lpe-item.h"
 #include "live_effects/lpeobject.h"
 #include "live_effects/parameter/parameter.h"
 #include <glibmm/ustring.h>
 #include "live_effects/lpe-text_label.h"
 #include "live_effects/lpe-path_length.h"
 #include "live_effects/lpe-line_segment.h"
+#include "live_effects/lpe-recursiveskeleton.h"
+#include "live_effects/lpe-extrude.h"
+#include "live_effects/lpe-powerstroke.h"
 
-//#define LPE_ENABLE_TEST_EFFECTS
 
 namespace Inkscape {
 
@@ -78,37 +85,43 @@ const Util::EnumData<EffectType> LPETypeData[] = {
     // {constant defined in effect-enum.h, N_("name of your effect"), "name of your effect in SVG"}
 #ifdef LPE_ENABLE_TEST_EFFECTS
     {DOEFFECTSTACK_TEST,    N_("doEffect stack test"),     "doeffectstacktest"},
-    {DYNASTROKE,            N_("Dynamic stroke"),          "dynastroke"},
-#endif
     {ANGLE_BISECTOR,        N_("Angle bisector"),          "angle_bisector"},
-    {BEND_PATH,             N_("Bend"),                     "bend_path"},
+    // TRANSLATORS: boolean operations
     {BOOLOPS,               N_("Boolops"),                 "boolops"},
     {CIRCLE_WITH_RADIUS,    N_("Circle (by center and radius)"),   "circle_with_radius"},
-    {CIRCLE_3PTS,           N_("Circle by 3 points"), "circle_3pts"},
-    {CONSTRUCT_GRID,        N_("Construct grid"),          "construct_grid"},
-    {ENVELOPE,              N_("Envelope Deformation"),    "envelope"},
-    {FREEHAND_SHAPE,        N_("Freehand Shape"),          "freehand_shape"}, // this is actually a special type of PatternAlongPath, used to paste shapes in pen/pencil tool
-    {GEARS,                 N_("Gears"),                   "gears"},
-    {ROUGH_HATCHES,         N_("Hatches (rough)"),            "rough_hatches"},
-    {INTERPOLATE,           N_("Interpolate Sub-Paths"),   "interpolate"},
-    {KNOT,                  N_("Knot"),                    "knot"},
+    {CIRCLE_3PTS,           N_("Circle by 3 points"),      "circle_3pts"},
+    {DYNASTROKE,            N_("Dynamic stroke"),          "dynastroke"},
+    {EXTRUDE,               N_("Extrude"),                 "extrude"},
     {LATTICE,               N_("Lattice Deformation"),     "lattice"},
     {LINE_SEGMENT,          N_("Line Segment"),            "line_segment"},
     {MIRROR_SYMMETRY,       N_("Mirror symmetry"),         "mirror_symmetry"},
     {OFFSET,                N_("Offset"),                  "offset"},
     {PARALLEL,              N_("Parallel"),                "parallel"},
     {PATH_LENGTH,           N_("Path length"),             "path_length"},
-    {PATTERN_ALONG_PATH,    N_("Pattern Along Path"),      "skeletal"},   // for historic reasons, this effect is called skeletal(strokes) in Inkscape:SVG
     {PERP_BISECTOR,         N_("Perpendicular bisector"),  "perp_bisector"},
     {PERSPECTIVE_PATH,      N_("Perspective path"),        "perspective_path"},
+    {POWERSTROKE,           N_("Power stroke"),            "powerstroke"},
     {COPY_ROTATE,           N_("Rotate copies"),           "copy_rotate"},
-    {RULER,                 N_("Ruler"),                   "ruler"},
-    {SKETCH,                N_("Sketch"),                  "sketch"},
-    {SPIRO,                 N_("Spiro spline"),            "spiro"},
-    {CURVE_STITCH,          N_("Stitch Sub-Paths"),        "curvestitching"},
+    {RECURSIVE_SKELETON,    N_("Recursive skeleton"),      "recursive_skeleton"},
     {TANGENT_TO_CURVE,      N_("Tangent to curve"),        "tangent_to_curve"},
     {TEXT_LABEL,            N_("Text label"),              "text_label"},
+#endif
+/* 0.46 */
+    {BEND_PATH,             N_("Bend"),                     "bend_path"},
+    {GEARS,                 N_("Gears"),                   "gears"},
+    {PATTERN_ALONG_PATH,    N_("Pattern Along Path"),      "skeletal"},   // for historic reasons, this effect is called skeletal(strokes) in Inkscape:SVG
+    {CURVE_STITCH,          N_("Stitch Sub-Paths"),        "curvestitching"},
+/* 0.47 */
     {VONKOCH,               N_("VonKoch"),                 "vonkoch"},
+    {KNOT,                  N_("Knot"),                    "knot"},
+    {CONSTRUCT_GRID,        N_("Construct grid"),          "construct_grid"},
+    {SPIRO,                 N_("Spiro spline"),            "spiro"},
+    {ENVELOPE,              N_("Envelope Deformation"),    "envelope"},
+    {INTERPOLATE,           N_("Interpolate Sub-Paths"),   "interpolate"},
+    {ROUGH_HATCHES,         N_("Hatches (rough)"),         "rough_hatches"},
+    {SKETCH,                N_("Sketch"),                  "sketch"},
+    {RULER,                 N_("Ruler"),                   "ruler"},
+/* 0.49 */
 };
 const Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, sizeof(LPETypeData)/sizeof(*LPETypeData));
 
@@ -133,9 +146,6 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
         case PATTERN_ALONG_PATH:
             neweffect = static_cast<Effect*> ( new LPEPatternAlongPath(lpeobj) );
             break;
-        case FREEHAND_SHAPE:
-            neweffect = static_cast<Effect*> ( new LPEFreehandShape(lpeobj) );
-            break;
         case BEND_PATH:
             neweffect = static_cast<Effect*> ( new LPEBendPath(lpeobj) );
             break;
@@ -223,6 +233,15 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
         case DYNASTROKE:
             neweffect = static_cast<Effect*> ( new LPEDynastroke(lpeobj) );
             break;
+        case RECURSIVE_SKELETON:
+            neweffect = static_cast<Effect*> ( new LPERecursiveSkeleton(lpeobj) );
+            break;
+        case EXTRUDE:
+            neweffect = static_cast<Effect*> ( new LPEExtrude(lpeobj) );
+            break;
+        case POWERSTROKE:
+            neweffect = static_cast<Effect*> ( new LPEPowerStroke(lpeobj) );
+            break;
         default:
             g_warning("LivePathEffect::Effect::New   called with invalid patheffect type (%d)", lpenr);
             neweffect = NULL;
@@ -236,11 +255,10 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
     return neweffect;
 }
 
-void
-Effect::createAndApply(const char* name, SPDocument *doc, SPItem *item)
+void Effect::createAndApply(const char* name, SPDocument *doc, SPItem *item)
 {
     // Path effect definition
-    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+    Inkscape::XML::Document *xml_doc = doc->getReprDoc();
     Inkscape::XML::Node *repr = xml_doc->createElement("inkscape:path-effect");
     repr->setAttribute("effect", name);
 
@@ -262,7 +280,6 @@ Effect::createAndApply(EffectType type, SPDocument *doc, SPItem *item)
 Effect::Effect(LivePathEffectObject *lpeobject)
     : oncanvasedit_it(0),
       is_visible(_("Is visible?"), _("If unchecked, the effect remains applied to the object but is temporarily disabled on canvas"), "is_visible", &wr, this, true),
-      deactivate_knotholder(_("Deactivate knotholder?"), _("Check this to deactivate knotholder handles (useful if they interfere with node handles during editing)"), "deactivate_knotholder", &wr, this, false),
       show_orig_path(false),
       lpeobj(lpeobject),
       concatenate_before_pwd2(false),
@@ -270,7 +287,7 @@ Effect::Effect(LivePathEffectObject *lpeobject)
       is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden
 {
     registerParameter( dynamic_cast<Parameter *>(&is_visible) );
-    registerParameter( dynamic_cast<Parameter *>(&deactivate_knotholder) );
+    is_visible.widget_is_visible = false;
 }
 
 Effect::~Effect()
@@ -461,9 +478,6 @@ void
 Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
     using namespace Inkscape::LivePathEffect;
 
-    if (deactivate_knotholder)
-        return;
-
     // add handles provided by the effect itself
     addKnotHolderEntities(knotholder, desktop, item);
 
@@ -500,7 +514,7 @@ Effect::getHelperPaths(SPLPEItem *lpeitem)
     std::vector<Geom::PathVector> hp_vec;
 
     if (!SP_IS_SHAPE(lpeitem)) {
-        g_print ("How to handle helperpaths for non-shapes?\n"); // non-shapes are for example SPGroups.
+//        g_print ("How to handle helperpaths for non-shapes?\n"); // non-shapes are for example SPGroups.
         return hp_vec;
     }
 
@@ -508,7 +522,7 @@ Effect::getHelperPaths(SPLPEItem *lpeitem)
     //       rather than copying PathVectors all over the place
     if (show_orig_path) {
         // add original path to helperpaths
-        SPCurve* curve = sp_shape_get_curve (SP_SHAPE(lpeitem));
+        SPCurve* curve = SP_SHAPE(lpeitem)->getCurve ();
         hp_vec.push_back(curve->get_pathvector());
     }
 
@@ -546,13 +560,15 @@ Effect::newWidget(Gtk::Tooltips * tooltips)
 
     std::vector<Parameter *>::iterator it = param_vector.begin();
     while (it != param_vector.end()) {
-        Parameter * param = *it;
-        Gtk::Widget * widg = param->param_newWidget(tooltips);
-        Glib::ustring * tip = param->param_getTooltip();
-        if (widg) {
-           vbox->pack_start(*widg, true, true, 2);
-            if (tip != NULL) {
-                tooltips->set_tip(*widg, *tip);
+        if ((*it)->widget_is_visible) {
+            Parameter * param = *it;
+            Gtk::Widget * widg = param->param_newWidget(tooltips);
+            Glib::ustring * tip = param->param_getTooltip();
+            if (widg) {
+                vbox->pack_start(*widg, true, true, 2);
+                if (tip != NULL) {
+                    tooltips->set_tip(*widg, *tip);
+                }
             }
         }
 
@@ -644,14 +660,11 @@ Effect::editNextParamOncanvas(SPItem * item, SPDesktop * desktop)
 void
 Effect::resetDefaults(SPItem * /*item*/)
 {
-    // do nothing for simple effects
-}
-
-void
-Effect::setup_nodepath(Inkscape::NodePath::Path *np)
-{
-    np->helperpath_rgba = 0xff0000ff;
-    np->helperpath_width = 1.0;
+    std::vector<Inkscape::LivePathEffect::Parameter *>::iterator p;
+    for (p = param_vector.begin(); p != param_vector.end(); ++p) {
+        (*p)->param_set_default();
+        (*p)->write_to_SVG();
+    }
 }
 
 void
@@ -664,7 +677,6 @@ Effect::transform_multiply(Geom::Matrix const& postmul, bool set)
     }
 }
 
-// TODO: take _all_ parameters into account, not only PointParams
 bool
 Effect::providesKnotholder()
 {