summaryrefslogtreecommitdiffstats
path: root/src/live_effects
diff options
context:
space:
mode:
authorLiam P. White <inkscapebrony@gmail.com>2014-10-18 21:44:39 +0000
committerLiam P. White <inkscapebrony@gmail.com>2014-10-18 21:44:39 +0000
commit68136c8b24a6995976db963a790207858e9baba5 (patch)
tree550e81af7c8d626ec80a2be5efec66dd10d84bc4 /src/live_effects
parentUpdate to experimental r13598 (diff)
parentUpdate to trunk r13621 (diff)
downloadinkscape-68136c8b24a6995976db963a790207858e9baba5.tar.gz
inkscape-68136c8b24a6995976db963a790207858e9baba5.zip
Update to experimental r13619
(bzr r13341.5.18)
Diffstat (limited to 'src/live_effects')
-rw-r--r--src/live_effects/CMakeLists.txt5
-rw-r--r--src/live_effects/Makefile_insert6
-rw-r--r--src/live_effects/effect-enum.h2
-rw-r--r--src/live_effects/effect.cpp8
-rw-r--r--src/live_effects/lpe-bspline.cpp126
-rw-r--r--src/live_effects/lpe-bspline.h18
-rw-r--r--src/live_effects/lpe-perspective-envelope.cpp (renamed from src/live_effects/lpe-envelope-perspective.cpp)132
-rw-r--r--src/live_effects/lpe-perspective-envelope.h (renamed from src/live_effects/lpe-envelope-perspective.h)26
-rw-r--r--src/live_effects/lpe-vonkoch.cpp6
9 files changed, 154 insertions, 175 deletions
diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt
index 30c2b2f41..c8a02c810 100644
--- a/src/live_effects/CMakeLists.txt
+++ b/src/live_effects/CMakeLists.txt
@@ -15,7 +15,6 @@ set(live_effects_SRC
lpe-dynastroke.cpp
lpe-ellipse-5pts.cpp
lpe-envelope.cpp
- lpe-envelope-perspective.cpp
lpe-extrude.cpp
lpe-fill-between-many.cpp
lpe-fill-between-strokes.cpp
@@ -32,6 +31,7 @@ set(live_effects_SRC
lpe-patternalongpath.cpp
lpe-perp_bisector.cpp
lpe-perspective_path.cpp
+ lpe-perspective-envelope.cpp
lpe-powerstroke.cpp
lpe-recursiveskeleton.cpp
lpe-rough-hatches.cpp
@@ -47,7 +47,6 @@ set(live_effects_SRC
lpe-bspline.cpp
lpe-text_label.cpp
lpe-vonkoch.cpp
- lpe-envelope-perspective.cpp
lpegroupbbox.cpp
lpeobject-reference.cpp
lpeobject.cpp
@@ -106,6 +105,7 @@ set(live_effects_SRC
lpe-patternalongpath.h
lpe-perp_bisector.h
lpe-perspective_path.h
+ lpe-perspective-envelope.h
lpe-powerstroke.h
lpe-powerstroke-interpolators.h
lpe-recursiveskeleton.h
@@ -122,7 +122,6 @@ set(live_effects_SRC
lpe-bspline.h
lpe-text_label.h
lpe-vonkoch.h
- lpe-envelope-perspective.h
lpegroupbbox.h
lpeobject-reference.h
lpeobject.h
diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert
index f18dcdef0..8f0a3ac57 100644
--- a/src/live_effects/Makefile_insert
+++ b/src/live_effects/Makefile_insert
@@ -70,6 +70,8 @@ ink_common_sources += \
live_effects/lpe-circle_with_radius.h \
live_effects/lpe-perspective_path.cpp \
live_effects/lpe-perspective_path.h \
+ live_effects/lpe-perspective-envelope.cpp \
+ live_effects/lpe-perspective-envelope.h \
live_effects/lpe-mirror_symmetry.cpp \
live_effects/lpe-mirror_symmetry.h \
live_effects/lpe-circle_3pts.cpp \
@@ -112,6 +114,4 @@ ink_common_sources += \
live_effects/lpe-jointype.cpp \
live_effects/lpe-jointype.h \
live_effects/lpe-taperstroke.cpp \
- live_effects/lpe-taperstroke.h \
- live_effects/lpe-envelope-perspective.cpp \
- live_effects/lpe-envelope-perspective.h
+ live_effects/lpe-taperstroke.h
diff --git a/src/live_effects/effect-enum.h b/src/live_effects/effect-enum.h
index c53f1a5b9..383eec19e 100644
--- a/src/live_effects/effect-enum.h
+++ b/src/live_effects/effect-enum.h
@@ -63,7 +63,7 @@ enum EffectType {
BOUNDING_BOX,
JOIN_TYPE,
TAPER_STROKE,
- ENVELOPE_PERSPECTIVE,
+ PERSPECTIVE_ENVELOPE,
FILLET_CHAMFER,
INVALID_LPE // This must be last (I made it such that it is not needed anymore I think..., Don't trust on it being last. - johan)
};
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index 22f688873..b002eaf7f 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -25,6 +25,7 @@
#include "live_effects/lpe-curvestitch.h"
#include "live_effects/lpe-circle_with_radius.h"
#include "live_effects/lpe-perspective_path.h"
+#include "live_effects/lpe-perspective-envelope.h"
#include "live_effects/lpe-spiro.h"
#include "live_effects/lpe-lattice.h"
#include "live_effects/lpe-lattice2.h"
@@ -60,7 +61,6 @@
#include "live_effects/lpe-bounding-box.h"
#include "live_effects/lpe-jointype.h"
#include "live_effects/lpe-taperstroke.h"
-#include "live_effects/lpe-envelope-perspective.h"
#include "live_effects/lpe-fillet-chamfer.h"
#include "xml/node-event-vector.h"
@@ -152,7 +152,7 @@ const Util::EnumData<EffectType> LPETypeData[] = {
/* 0.91 */
{SIMPLIFY, N_("Simplify"), "simplify"},
{LATTICE2, N_("Lattice Deformation 2"), "lattice2"},
- {ENVELOPE_PERSPECTIVE, N_("Envelope-Perspective"), "envelope-perspective"},
+ {PERSPECTIVE_ENVELOPE, N_("Perspective/Envelope"), "perspective-envelope"},
{FILLET_CHAMFER, N_("Fillet/Chamfer"), "fillet-chamfer"},
{INTERPOLATE_POINTS, N_("Interpolate points"), "interpolate_points"},
};
@@ -311,8 +311,8 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
case LATTICE2:
neweffect = static_cast<Effect*> ( new LPELattice2(lpeobj) );
break;
- case ENVELOPE_PERSPECTIVE:
- neweffect = static_cast<Effect*> ( new LPEEnvelopePerspective(lpeobj) );
+ case PERSPECTIVE_ENVELOPE:
+ neweffect = static_cast<Effect*> ( new LPEPerspectiveEnvelope(lpeobj) );
break;
case FILLET_CHAMFER:
neweffect = static_cast<Effect*> ( new LPEFilletChamfer(lpeobj) );
diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp
index 5ba0d697b..7703b8221 100644
--- a/src/live_effects/lpe-bspline.cpp
+++ b/src/live_effects/lpe-bspline.cpp
@@ -59,17 +59,22 @@ const double noPower = 0.0;
const double defaultStartPower = 0.3334;
const double defaultEndPower = 0.6667;
-LPEBSpline::LPEBSpline(LivePathEffectObject *lpeobject) :
- Effect(lpeobject),
- steps(_("Steps whith CTRL:"), _("Change number of steps whith CTRL pressed"), "steps", &wr, this, 2),
- ignoreCusp(_("Ignore cusp nodes"), _("Change ignoring cusp nodes"), "ignoreCusp", &wr, this, true),
- onlySelected(_("Change only selected nodes"), _("Change only selected nodes"), "onlySelected", &wr, this, false),
- weight(_("Change weight:"), _("Change weight of the effect"), "weight", &wr, this, defaultStartPower)
+LPEBSpline::LPEBSpline(LivePathEffectObject *lpeobject)
+ : Effect(lpeobject),
+ // initialise your parameters here:
+ //testpointA(_("Test Point A"), _("Test A"), "ptA", &wr, this,
+ //Geom::Point(100,100)),
+ steps(_("Steps whith CTRL:"), _("Change number of steps whith CTRL pressed"), "steps", &wr, this, 2),
+ ignoreCusp(_("Ignore cusp nodes"), _("Change ignoring cusp nodes"), "ignoreCusp", &wr, this, true),
+ onlySelected(_("Change only selected nodes"), _("Change only selected nodes"), "onlySelected", &wr, this, false),
+ showHelper(_("Show helper paths"), _("Show helper paths"), "showHelper", &wr, this, false),
+ weight(_("Change weight:"), _("Change weight of the effect"), "weight", &wr, this, defaultStartPower)
{
- registerParameter(&weight);
- registerParameter(&steps);
- registerParameter(&ignoreCusp);
- registerParameter(&onlySelected);
+ registerParameter(dynamic_cast<Parameter *>(&weight));
+ registerParameter(dynamic_cast<Parameter *>(&steps));
+ registerParameter(dynamic_cast<Parameter *>(&ignoreCusp));
+ registerParameter(dynamic_cast<Parameter *>(&onlySelected));
+ registerParameter(dynamic_cast<Parameter *>(&showHelper));
weight.param_set_range(noPower, 1);
weight.param_set_increments(0.1, 0.1);
@@ -89,7 +94,9 @@ void LPEBSpline::doBeforeEffect (SPLPEItem const* lpeitem)
}
}
-void LPEBSpline::createAndApply(const char *name, SPDocument *doc, SPItem *item)
+
+void LPEBSpline::createAndApply(const char *name, SPDocument *doc,
+ SPItem *item)
{
if (!SP_IS_SHAPE(item)) {
g_warning("LPE BSpline can only be applied to shapes (not groups).");
@@ -99,7 +106,8 @@ void LPEBSpline::createAndApply(const char *name, SPDocument *doc, SPItem *item)
Inkscape::XML::Node *repr = xml_doc->createElement("inkscape:path-effect");
repr->setAttribute("effect", name);
- doc->getDefs()->getRepr()->addChild(repr, NULL); // adds to <defs> and assigns the 'id' attribute
+ doc->getDefs()->getRepr()
+ ->addChild(repr, NULL); // adds to <defs> and assigns the 'id' attribute
const gchar *repr_id = repr->attribute("id");
Inkscape::GC::release(repr);
@@ -111,13 +119,13 @@ void LPEBSpline::createAndApply(const char *name, SPDocument *doc, SPItem *item)
void LPEBSpline::doEffect(SPCurve *curve)
{
+
if (curve->get_segment_count() < 1){
return;
}
-
+ // Make copy of old path as it is changed during processing
Geom::PathVector const original_pathv = curve->get_pathvector();
curve->reset();
-
double radiusHelperNodes = 6.0;
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
if (desktop){
@@ -125,7 +133,6 @@ void LPEBSpline::doEffect(SPCurve *curve)
SPNamedView *nv = sp_desktop_namedview(desktop);
radiusHelperNodes = Inkscape::Util::Quantity::convert(radiusHelperNodes, "px", nv->doc_units->abbr);
}
-
for (Geom::PathVector::const_iterator path_it = original_pathv.begin();
path_it != original_pathv.end(); ++path_it) {
if (path_it->empty())
@@ -133,7 +140,7 @@ void LPEBSpline::doEffect(SPCurve *curve)
Geom::Path::const_iterator curve_it1 = path_it->begin();
Geom::Path::const_iterator curve_it2 = ++(path_it->begin());
- Geom::Path::const_iterator curve_endit = path_it->end_default();
+ Geom::Path::const_iterator curve_endit = path_it->end_default();
SPCurve *nCurve = new SPCurve();
Geom::Point previousNode(0, 0);
Geom::Point node(0, 0);
@@ -145,13 +152,29 @@ void LPEBSpline::doEffect(SPCurve *curve)
Geom::D2<Geom::SBasis> SBasisHelper;
Geom::CubicBezier const *cubic = NULL;
if (path_it->closed()) {
- const Geom::Curve &closingline = path_it->back_closed();
+ // if the path is closed, maybe we have to stop a bit earlier because the
+ // closing line segment has zerolength.
+ const Geom::Curve &closingline =
+ path_it->back_closed(); // the closing line segment is always of type
+ // Geom::LineSegment.
if (are_near(closingline.initialPoint(), closingline.finalPoint())) {
+ // closingline.isDegenerate() did not work, because it only checks for
+ // *exact* zero length, which goes wrong for relative coordinates and
+ // rounding errors...
+ // the closing line segment has zero-length. So stop before that one!
curve_endit = path_it->end_open();
}
}
+ //Si la curva está cerrada calculamos el punto donde
+ //deveria estar el nodo BSpline de cierre/inicio de la curva
+ //en posible caso de que se cierre con una linea recta creando un nodo
+ //BSPline
nCurve->moveto(curve_it1->initialPoint());
+ //Recorremos todos los segmentos menos el último
while (curve_it1 != curve_endit) {
+ //previousPointAt3 = pointAt3;
+ //Calculamos los puntos que dividirían en tres segmentos iguales el path
+ //recto de entrada y de salida
SPCurve *in = new SPCurve();
in->moveto(curve_it1->initialPoint());
in->lineto(curve_it1->finalPoint());
@@ -192,7 +215,6 @@ void LPEBSpline::doEffect(SPCurve *curve)
out->reset();
delete out;
}
- Geom::Point startNode = path_it->begin()->initialPoint();
if (path_it->closed() && curve_it2 == curve_endit) {
SPCurve *start = new SPCurve();
start->moveto(path_it->begin()->initialPoint());
@@ -225,9 +247,9 @@ void LPEBSpline::doEffect(SPCurve *curve)
SBasisHelper = lineHelper->first_segment()->toSBasis();
lineHelper->reset();
delete lineHelper;
- startNode = SBasisHelper.valueAt(0.5);
- nCurve->curveto(pointAt1, pointAt2, startNode);
- nCurve->move_endpoints(startNode, startNode);
+ node = SBasisHelper.valueAt(0.5);
+ nCurve->curveto(pointAt1, pointAt2, node);
+ nCurve->move_endpoints(node, node);
} else if ( curve_it2 == curve_endit) {
nCurve->curveto(pointAt1, pointAt2, curve_it1->finalPoint());
nCurve->move_endpoints(path_it->begin()->initialPoint(), curve_it1->finalPoint());
@@ -238,17 +260,26 @@ void LPEBSpline::doEffect(SPCurve *curve)
SBasisHelper = lineHelper->first_segment()->toSBasis();
lineHelper->reset();
delete lineHelper;
+ //almacenamos el punto del anterior bucle -o el de cierre- que nos hara de
+ //principio de curva
previousNode = node;
+ //Y este hará de final de curva
node = SBasisHelper.valueAt(0.5);
Geom::CubicBezier const *cubic2 = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1);
if((cubic && are_near((*cubic)[0],(*cubic)[1])) || (cubic2 && are_near((*cubic2)[2],(*cubic2)[3]))) {
node = curve_it1->finalPoint();
}
nCurve->curveto(pointAt1, pointAt2, node);
- if(!are_near(node,curve_it1->finalPoint())){
- drawHandle(node, radiusHelperNodes);
- }
}
+ if(!are_near(node,curve_it1->finalPoint()) && showHelper){
+ drawHandle(node, radiusHelperNodes);
+ }
+ //La curva BSpline se forma calculando el centro del segmanto de unión
+ //de el punto situado en las 2/3 partes de el segmento de entrada
+ //con el punto situado en la posición 1/3 del segmento de salida
+ //Estos dos puntos ademas estan posicionados en el lugas correspondiente
+ //de los manejadores de la curva
+ //aumentamos los valores para el siguiente paso en el bucle
++curve_it1;
++curve_it2;
}
@@ -259,6 +290,8 @@ void LPEBSpline::doEffect(SPCurve *curve)
curve->append(nCurve, false);
nCurve->reset();
delete nCurve;
+ }
+ if(showHelper){
Geom::PathVector const pathv = curve->get_pathvector();
hp.push_back(pathv[0]);
}
@@ -293,32 +326,44 @@ Gtk::Widget *LPEBSpline::newWidget()
while (it != param_vector.end()) {
if ((*it)->widget_is_visible) {
Parameter *param = *it;
- Gtk::Widget *widg = Gtk::manage(param->param_newWidget());
+ Gtk::Widget *widg = dynamic_cast<Gtk::Widget *>(param->param_newWidget());
if (param->param_key == "weight") {
- Gtk::HBox * buttons = Gtk::manage(new Gtk::HBox(true, 0));
-
- Gtk::Button *defaultWeight = Gtk::manage(new Gtk::Button(Glib::ustring(_("Default weight"))));
- defaultWeight->signal_clicked().connect(sigc::bind<Gtk::Widget *>(sigc::mem_fun(*this, &LPEBSpline::toDefaultWeight), widg));
+ Gtk::HBox * buttons = Gtk::manage(new Gtk::HBox(true,0));
+ Gtk::Button *defaultWeight =
+ Gtk::manage(new Gtk::Button(Glib::ustring(_("Default weight"))));
+ defaultWeight->signal_clicked()
+ .connect(sigc::bind<Gtk::Widget *>(sigc::mem_fun(*this, &LPEBSpline::toDefaultWeight), widg));
buttons->pack_start(*defaultWeight, true, true, 2);
-
- Gtk::Button *makeCusp = Gtk::manage(new Gtk::Button(Glib::ustring(_("Make cusp"))));
- makeCusp->signal_clicked().connect(sigc::bind<Gtk::Widget *>(sigc::mem_fun(*this, &LPEBSpline::toMakeCusp), widg));
+ Gtk::Button *makeCusp =
+ Gtk::manage(new Gtk::Button(Glib::ustring(_("Make cusp"))));
+ makeCusp->signal_clicked()
+ .connect(sigc::bind<Gtk::Widget *>(sigc::mem_fun(*this, &LPEBSpline::toMakeCusp), widg));
buttons->pack_start(*makeCusp, true, true, 2);
-
vbox->pack_start(*buttons, true, true, 2);
}
if (param->param_key == "weight" || param->param_key == "steps") {
- Inkscape::UI::Widget::Scalar *widgRegistered = Gtk::manage(dynamic_cast<Inkscape::UI::Widget::Scalar *>(widg));
- widgRegistered->signal_value_changed().connect(sigc::mem_fun(*this, &LPEBSpline::toWeight));
-
+ Inkscape::UI::Widget::Scalar *widgRegistered =
+ Gtk::manage(dynamic_cast<Inkscape::UI::Widget::Scalar *>(widg));
+ widgRegistered->signal_value_changed()
+ .connect(sigc::mem_fun(*this, &LPEBSpline::toWeight));
+ widg = dynamic_cast<Gtk::Widget *>(widgRegistered);
if (widg) {
Gtk::HBox * scalarParameter = dynamic_cast<Gtk::HBox *>(widg);
- std::vector<Gtk::Widget *> childList = scalarParameter->get_children();
+ std::vector< Gtk::Widget* > childList = scalarParameter->get_children();
Gtk::Entry* entryWidg = dynamic_cast<Gtk::Entry *>(childList[1]);
entryWidg->set_width_chars(6);
}
}
-
+ if (param->param_key == "onlySelected") {
+ Gtk::CheckButton *widgRegistered =
+ Gtk::manage(dynamic_cast<Gtk::CheckButton *>(widg));
+ widg = dynamic_cast<Gtk::Widget *>(widgRegistered);
+ }
+ if (param->param_key == "ignoreCusp") {
+ Gtk::CheckButton *widgRegistered =
+ Gtk::manage(dynamic_cast<Gtk::CheckButton *>(widg));
+ widg = dynamic_cast<Gtk::Widget *>(widgRegistered);
+ }
Glib::ustring *tip = param->param_getTooltip();
if (widg) {
vbox->pack_start(*widg, true, true, 2);
@@ -333,7 +378,7 @@ Gtk::Widget *LPEBSpline::newWidget()
++it;
}
- return vbox;
+ return dynamic_cast<Gtk::Widget *>(vbox);
}
void LPEBSpline::toDefaultWeight(Gtk::Widget *widgWeight)
@@ -379,7 +424,8 @@ void LPEBSpline::changeWeight(double weightValue)
g_free(str);
curve->unref();
desktop->clearWaitingCursor();
- DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_LPE, _("Modified the weight of a BSpline"));
+ DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_LPE,
+ _("Modified the weight of the BSpline"));
}
bool LPEBSpline::nodeIsSelected(Geom::Point nodePoint)
diff --git a/src/live_effects/lpe-bspline.h b/src/live_effects/lpe-bspline.h
index e066015ad..169658b94 100644
--- a/src/live_effects/lpe-bspline.h
+++ b/src/live_effects/lpe-bspline.h
@@ -24,19 +24,16 @@ public:
return SUPPRESS_FLASH;
}
virtual void doEffect(SPCurve *curve);
- virtual void doBeforeEffect(SPLPEItem const* lpeitem);
+ virtual void doBeforeEffect (SPLPEItem const* lpeitem);
void drawHandle(Geom::Point p, double radiusHelperNodes);
void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec);
-
- void doBSplineFromWidget(SPCurve *curve, double value);
- bool nodeIsSelected(Geom::Point nodePoint);
-
+ virtual void doBSplineFromWidget(SPCurve *curve, double value);
+ virtual bool nodeIsSelected(Geom::Point nodePoint);
virtual Gtk::Widget *newWidget();
-
- void changeWeight(double weightValue);
- void toDefaultWeight(Gtk::Widget *widgWeight);
- void toMakeCusp(Gtk::Widget *widgWeight);
- void toWeight();
+ virtual void changeWeight(double weightValue);
+ virtual void toDefaultWeight(Gtk::Widget *widgWeight);
+ virtual void toMakeCusp(Gtk::Widget *widgWeight);
+ virtual void toWeight();
// TODO make this private
ScalarParam steps;
@@ -45,6 +42,7 @@ private:
std::vector<Geom::Point> points;
BoolParam ignoreCusp;
BoolParam onlySelected;
+ BoolParam showHelper;
ScalarParam weight;
Geom::PathVector hp;
diff --git a/src/live_effects/lpe-envelope-perspective.cpp b/src/live_effects/lpe-perspective-envelope.cpp
index 378ef5a92..6f6838c81 100644
--- a/src/live_effects/lpe-envelope-perspective.cpp
+++ b/src/live_effects/lpe-perspective-envelope.cpp
@@ -1,5 +1,5 @@
/** \file
- * LPE <envelope-perspective> implementation
+ * LPE <perspective-envelope> implementation
*/
/*
@@ -15,7 +15,7 @@
*/
#include <gtkmm.h>
-#include "live_effects/lpe-envelope-perspective.h"
+#include "live_effects/lpe-perspective-envelope.h"
#include "helper/geom.h"
#include "display/curve.h"
#include "svg/svg.h"
@@ -29,21 +29,21 @@ namespace Inkscape {
namespace LivePathEffect {
enum DeformationType {
- DEFORMATION_ENVELOPE,
- DEFORMATION_PERSPECTIVE
+ DEFORMATION_PERSPECTIVE,
+ DEFORMATION_ENVELOPE
};
static const Util::EnumData<unsigned> DeformationTypeData[] = {
- {DEFORMATION_ENVELOPE , N_("Envelope deformation"), "Envelope deformation"},
- {DEFORMATION_PERSPECTIVE , N_("Perspective"), "Perspective"}
+ {DEFORMATION_PERSPECTIVE , N_("Perspective"), "Perspective"},
+ {DEFORMATION_ENVELOPE , N_("Envelope deformation"), "Envelope deformation"}
};
static const Util::EnumDataConverter<unsigned> DeformationTypeConverter(DeformationTypeData, sizeof(DeformationTypeData)/sizeof(*DeformationTypeData));
-LPEEnvelopePerspective::LPEEnvelopePerspective(LivePathEffectObject *lpeobject) :
+LPEPerspectiveEnvelope::LPEPerspectiveEnvelope(LivePathEffectObject *lpeobject) :
Effect(lpeobject),
// initialise your parameters here:
- deform_type(_("Type"), _("Select the type of deformation"), "deform_type", DeformationTypeConverter, &wr, this, DEFORMATION_ENVELOPE),
+ deform_type(_("Type"), _("Select the type of deformation"), "deform_type", DeformationTypeConverter, &wr, this, DEFORMATION_PERSPECTIVE),
Up_Left_Point(_("Top Left"), _("Top Left - Ctrl+Alt+Click to reset"), "Up_Left_Point", &wr, this),
Up_Right_Point(_("Top Right"), _("Top Right - Ctrl+Alt+Click to reset"), "Up_Right_Point", &wr, this),
Down_Left_Point(_("Down Left"), _("Down Left - Ctrl+Alt+Click to reset"), "Down_Left_Point", &wr, this),
@@ -57,11 +57,11 @@ LPEEnvelopePerspective::LPEEnvelopePerspective(LivePathEffectObject *lpeobject)
registerParameter( dynamic_cast<Parameter *>(&Down_Right_Point) );
}
-LPEEnvelopePerspective::~LPEEnvelopePerspective()
+LPEPerspectiveEnvelope::~LPEPerspectiveEnvelope()
{
}
-void LPEEnvelopePerspective::doEffect(SPCurve *curve) {
+void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) {
using Geom::X;
using Geom::Y;
double projmatrix[3][3];
@@ -135,32 +135,23 @@ void LPEEnvelopePerspective::doEffect(SPCurve *curve) {
continue;
//Itreadores
SPCurve *nCurve = new SPCurve();
- Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve
- Geom::Path::const_iterator curve_it2 =
- ++(path_it->begin()); // outgoing curve
- Geom::Path::const_iterator curve_endit =
- path_it->end_default(); // this determines when the loop has to stop
+ Geom::Path::const_iterator curve_it1 = path_it->begin();
+ Geom::Path::const_iterator curve_it2 = ++(path_it->begin());
+ Geom::Path::const_iterator curve_endit = path_it->end_default();
if (path_it->closed()) {
- // if the path is closed, maybe we have to stop a bit earlier because the
- // closing line segment has zerolength.
- const Geom::Curve &closingline =
- path_it->back_closed(); // the closing line segment is always of type
- // Geom::LineSegment.
- if (are_near(closingline.initialPoint(), closingline.finalPoint())) {
- // closingline.isDegenerate() did not work, because it only checks for
- // *exact* zero length, which goes wrong for relative coordinates and
- // rounding errors...
- // the closing line segment has zero-length. So stop before that one!
- curve_endit = path_it->end_open();
- }
+ const Geom::Curve &closingline =
+ path_it->back_closed();
+ if (are_near(closingline.initialPoint(), closingline.finalPoint())) {
+ curve_endit = path_it->end_open();
+ }
}
if(deform_type == DEFORMATION_PERSPECTIVE){
nCurve->moveto(project_point(curve_it1->initialPoint(),projmatrix));
}else{
nCurve->moveto(project_point(curve_it1->initialPoint()));
}
- while (curve_it2 != curve_endit) {
+ while (curve_it1 != curve_endit) {
cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1);
if (cubic) {
pointAt1 = (*cubic)[1];
@@ -181,34 +172,13 @@ void LPEEnvelopePerspective::doEffect(SPCurve *curve) {
}
nCurve->curveto(pointAt1, pointAt2, pointAt3);
++curve_it1;
- ++curve_it2;
- }
- cubic = dynamic_cast<Geom::CubicBezier const *>(&*curve_it1);
- if (cubic) {
- pointAt1 = (*cubic)[1];
- pointAt2 = (*cubic)[2];
- } else {
- pointAt1 = curve_it1->initialPoint();
- pointAt2 = curve_it1->finalPoint();
- }
- pointAt3 = curve_it1->finalPoint();
- if(deform_type == DEFORMATION_PERSPECTIVE){
- pointAt1 = project_point(pointAt1,projmatrix);
- pointAt2 = project_point(pointAt2,projmatrix);
- pointAt3 = project_point(pointAt3,projmatrix);
- }else{
- pointAt1 = project_point(pointAt1);
- pointAt2 = project_point(pointAt2);
- pointAt3 = project_point(pointAt3);
- }
- nCurve->curveto(pointAt1, pointAt2, pointAt3);
- if(deform_type == DEFORMATION_PERSPECTIVE){
- nCurve->move_endpoints(project_point(path_it->begin()->initialPoint(),projmatrix), pointAt3);
- }else{
- nCurve->move_endpoints(project_point(path_it->begin()->initialPoint()), pointAt3);
+ if(curve_it2 != curve_endit) {
+ ++curve_it2;
+ }
}
//y cerramos la curva
if (path_it->closed()) {
+ nCurve->move_endpoints(pointAt3, pointAt3);
nCurve->closepath_current();
}
curve->append(nCurve, false);
@@ -218,11 +188,13 @@ void LPEEnvelopePerspective::doEffect(SPCurve *curve) {
}
Geom::Point
-LPEEnvelopePerspective::project_point(Geom::Point p){
+LPEPerspectiveEnvelope::project_point(Geom::Point p){
double width = boundingbox_X.extent();
double height = boundingbox_Y.extent();
- Geom::Coord xratio = abs(Geom::Point(boundingbox_X.min(), boundingbox_Y.max())[X]-p[X])/width;
- Geom::Coord yratio = abs(Geom::Point(boundingbox_X.min(), boundingbox_Y.max())[Y]-p[Y])/height;
+ double delta_x = boundingbox_X.min() - p[X];
+ double delta_y = boundingbox_Y.max() - p[Y];
+ Geom::Coord xratio = (delta_x * sgn(delta_x)) / width;
+ Geom::Coord yratio = (delta_y * sgn(delta_y)) / height;
Geom::Line* horiz = new Geom::Line();
Geom::Line* vert = new Geom::Line();
vert->setPoints (pointAtRatio(yratio,Down_Left_Point,Up_Left_Point),pointAtRatio(yratio,Down_Right_Point,Up_Right_Point));
@@ -237,7 +209,7 @@ LPEEnvelopePerspective::project_point(Geom::Point p){
}
Geom::Point
-LPEEnvelopePerspective::project_point(Geom::Point p, double m[][3]){
+LPEPerspectiveEnvelope::project_point(Geom::Point p, double m[][3]){
Geom::Coord x = p[0];
Geom::Coord y = p[1];
return Geom::Point(
@@ -246,7 +218,7 @@ LPEEnvelopePerspective::project_point(Geom::Point p, double m[][3]){
}
Geom::Point
-LPEEnvelopePerspective::pointAtRatio(Geom::Coord ratio,Geom::Point A, Geom::Point B){
+LPEPerspectiveEnvelope::pointAtRatio(Geom::Coord ratio,Geom::Point A, Geom::Point B){
Geom::Coord x = A[X] + (ratio * (B[X]-A[X]));
Geom::Coord y = A[Y]+ (ratio * (B[Y]-A[Y]));
return Point(x, y);
@@ -254,7 +226,7 @@ LPEEnvelopePerspective::pointAtRatio(Geom::Coord ratio,Geom::Point A, Geom::Poin
Gtk::Widget *
-LPEEnvelopePerspective::newWidget()
+LPEPerspectiveEnvelope::newWidget()
{
// use manage here, because after deletion of Effect object, others might still be pointing to this widget.
Gtk::VBox * vbox = Gtk::manage( new Gtk::VBox(Effect::newWidget()) );
@@ -285,20 +257,12 @@ LPEEnvelopePerspective::newWidget()
Gtk::Label* handles = Gtk::manage(new Gtk::Label(Glib::ustring(_("Handles:")),Gtk::ALIGN_START));
vbox->pack_start(*handles, false, false, 2);
hboxUpHandles->pack_start(*widg, true, true, 2);
-#if WITH_GTKMM_3_0
- hboxUpHandles->pack_start(*Gtk::manage(new Gtk::Separator(Gtk::ORIENTATION_VERTICAL)), Gtk::PACK_EXPAND_WIDGET);
-#else
hboxUpHandles->pack_start(*Gtk::manage(new Gtk::VSeparator()), Gtk::PACK_EXPAND_WIDGET);
-#endif
}else if(param->param_key == "Up_Right_Point"){
hboxUpHandles->pack_start(*widg, true, true, 2);
}else if(param->param_key == "Down_Left_Point"){
hboxDownHandles->pack_start(*widg, true, true, 2);
-#if WITH_GTKMM_3_0
- hboxDownHandles->pack_start(*Gtk::manage(new Gtk::Separator(Gtk::ORIENTATION_VERTICAL)), Gtk::PACK_EXPAND_WIDGET);
-#else
hboxDownHandles->pack_start(*Gtk::manage(new Gtk::VSeparator()), Gtk::PACK_EXPAND_WIDGET);
-#endif
}else{
hboxDownHandles->pack_start(*widg, true, true, 2);
}
@@ -327,18 +291,13 @@ LPEEnvelopePerspective::newWidget()
}
vbox->pack_start(*hboxUpHandles,true, true, 2);
Gtk::HBox * hboxMiddle = Gtk::manage(new Gtk::HBox(true,2));
-#if WITH_GTKMM_3_0
- hboxMiddle->pack_start(*Gtk::manage(new Gtk::Separator()), Gtk::PACK_EXPAND_WIDGET);
- hboxMiddle->pack_start(*Gtk::manage(new Gtk::Separator()), Gtk::PACK_EXPAND_WIDGET);
-#else
hboxMiddle->pack_start(*Gtk::manage(new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET);
hboxMiddle->pack_start(*Gtk::manage(new Gtk::HSeparator()), Gtk::PACK_EXPAND_WIDGET);
-#endif
vbox->pack_start(*hboxMiddle, false, true, 2);
vbox->pack_start(*hboxDownHandles, true, true, 2);
Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false,0));
Gtk::Button* resetButton = Gtk::manage(new Gtk::Button(Gtk::Stock::CLEAR));
- resetButton->signal_clicked().connect(sigc::mem_fun (*this,&LPEEnvelopePerspective::resetGrid));
+ resetButton->signal_clicked().connect(sigc::mem_fun (*this,&LPEPerspectiveEnvelope::resetGrid));
resetButton->set_size_request(140,45);
vbox->pack_start(*hbox, true,true,2);
hbox->pack_start(*resetButton, false, false,2);
@@ -346,17 +305,14 @@ LPEEnvelopePerspective::newWidget()
}
void
-LPEEnvelopePerspective::doBeforeEffect (SPLPEItem const* lpeitem)
+LPEPerspectiveEnvelope::doBeforeEffect (SPLPEItem const* lpeitem)
{
original_bbox(lpeitem);
setDefaults();
- SPLPEItem * item = const_cast<SPLPEItem*>(lpeitem);
- item->apply_to_clippath(item);
- item->apply_to_mask(item);
}
void
-LPEEnvelopePerspective::setDefaults()
+LPEPerspectiveEnvelope::setDefaults()
{
Geom::Point Up_Left(boundingbox_X.min(), boundingbox_Y.min());
Geom::Point Up_Right(boundingbox_X.max(), boundingbox_Y.min());
@@ -370,7 +326,7 @@ LPEEnvelopePerspective::setDefaults()
}
void
-LPEEnvelopePerspective::resetGrid()
+LPEPerspectiveEnvelope::resetGrid()
{
Up_Left_Point.param_set_and_write_default();
Up_Right_Point.param_set_and_write_default();
@@ -384,7 +340,7 @@ LPEEnvelopePerspective::resetGrid()
}
void
-LPEEnvelopePerspective::resetDefaults(SPItem const* item)
+LPEPerspectiveEnvelope::resetDefaults(SPItem const* item)
{
Effect::resetDefaults(item);
original_bbox(SP_LPE_ITEM(item));
@@ -393,19 +349,7 @@ LPEEnvelopePerspective::resetDefaults(SPItem const* item)
}
void
-LPEEnvelopePerspective::calculateCurve(Geom::Point a,Geom::Point b, SPCurve* c, bool horizontal, bool move)
-{
- using Geom::X;
- using Geom::Y;
- if(move) c->moveto(a);
- Geom::Point cubic1 = a + (1./3)* (b - a);
- Geom::Point cubic2 = b + (1./3)* (a - b);
- if(horizontal) c->curveto(Geom::Point(cubic1[X],a[Y]),Geom::Point(cubic2[X],b[Y]),b);
- else c->curveto(Geom::Point(a[X],cubic1[Y]),Geom::Point(b[X],cubic2[Y]),b);
-}
-
-void
-LPEEnvelopePerspective::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
+LPEPerspectiveEnvelope::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
{
hp_vec.clear();
@@ -437,4 +381,4 @@ LPEEnvelopePerspective::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::v
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+// vim: file_type=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/live_effects/lpe-envelope-perspective.h b/src/live_effects/lpe-perspective-envelope.h
index 0de9a0e35..2f253882e 100644
--- a/src/live_effects/lpe-envelope-perspective.h
+++ b/src/live_effects/lpe-perspective-envelope.h
@@ -1,8 +1,8 @@
-#ifndef INKSCAPE_LPE_ENVELOPE_PERSPECTIVE_H
-#define INKSCAPE_LPE_ENVELOPE_PERSPECTIVE_H
+#ifndef INKSCAPE_LPE_PERSPECTIVE_ENVELOPE_H
+#define INKSCAPE_LPE_PERSPECTIVE_ENVELOPE_H
/** \file
- * LPE <envelope-perspective> implementation , see lpe-envelope-perspective.cpp.
+ * LPE <perspective-envelope> implementation , see lpe-perspective-envelope.cpp.
*/
/*
@@ -25,11 +25,12 @@
namespace Inkscape {
namespace LivePathEffect {
-class LPEEnvelopePerspective : public Effect, GroupBBoxEffect {
+class LPEPerspectiveEnvelope : public Effect, GroupBBoxEffect {
public:
- LPEEnvelopePerspective(LivePathEffectObject *lpeobject);
- virtual ~LPEEnvelopePerspective();
+ LPEPerspectiveEnvelope(LivePathEffectObject *lpeobject);
+
+ virtual ~LPEPerspectiveEnvelope();
virtual void doEffect(SPCurve *curve);
@@ -37,7 +38,7 @@ public:
virtual Geom::Point project_point(Geom::Point p, double m[][3]);
- Geom::Point pointAtRatio(Geom::Coord ratio,Geom::Point A, Geom::Point B);
+ virtual Geom::Point pointAtRatio(Geom::Coord ratio,Geom::Point A, Geom::Point B);
virtual void resetDefaults(SPItem const* item);
@@ -45,17 +46,10 @@ public:
virtual Gtk::Widget * newWidget();
- virtual void calculateCurve(Geom::Point a,Geom::Point b, SPCurve *c, bool horizontal, bool move);
-
virtual void setDefaults();
virtual void resetGrid();
- //virtual void original_bbox(SPLPEItem const* lpeitem, bool absolute = false);
-
- //virtual void addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector<Geom::PathVector> &/*hp_vec*/);
-
- //virtual std::vector<Geom::PathVector> getHelperPaths(SPLPEItem const* lpeitem);
protected:
void addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec);
private:
@@ -66,8 +60,8 @@ private:
PointReseteableParam Down_Left_Point;
PointReseteableParam Down_Right_Point;
- LPEEnvelopePerspective(const LPEEnvelopePerspective&);
- LPEEnvelopePerspective& operator=(const LPEEnvelopePerspective&);
+ LPEPerspectiveEnvelope(const LPEPerspectiveEnvelope&);
+ LPEPerspectiveEnvelope& operator=(const LPEPerspectiveEnvelope&);
};
} //namespace LivePathEffect
diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp
index 7c1913076..b52816c87 100644
--- a/src/live_effects/lpe-vonkoch.cpp
+++ b/src/live_effects/lpe-vonkoch.cpp
@@ -132,8 +132,8 @@ LPEVonKoch::doEffect_path (std::vector<Geom::Path> const & path_in)
int path_in_complexity = 0;
for (unsigned k = 0; k < path_in.size(); k++){
path_in_complexity+=path_in[k].size();
- }
- double complexity = std::pow(transforms.size(),nbgenerations)*path_in_complexity;
+ }
+ double complexity = std::pow(transforms.size(), nbgenerations) * path_in_complexity;
if (drawall.get_value()){
int k = transforms.size();
if(k>1){
@@ -141,8 +141,6 @@ LPEVonKoch::doEffect_path (std::vector<Geom::Path> const & path_in)
}else{
complexity = nbgenerations*k*path_in_complexity;
}
- }else{
- complexity = std::pow(transforms.size(),nbgenerations)*path_in_complexity;
}
if (complexity > double(maxComplexity)){
g_warning("VonKoch lpe's output too complex. Effect bypassed.");