summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-bspline.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/live_effects/lpe-bspline.cpp')
-rw-r--r--src/live_effects/lpe-bspline.cpp156
1 files changed, 22 insertions, 134 deletions
diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp
index 7703b8221..fdaeaf897 100644
--- a/src/live_effects/lpe-bspline.cpp
+++ b/src/live_effects/lpe-bspline.cpp
@@ -24,11 +24,6 @@
#include "live_effects/lpeobject.h"
#include "live_effects/parameter/parameter.h"
#include "ui/widget/scalar.h"
-#include "ui/tool/node.h"
-#include "ui/tools/node-tool.h"
-#include "ui/tool/control-point-selection.h"
-#include "ui/tool/selectable-control-point.h"
-#include "selection.h"
#include "xml/repr.h"
#include "svg/svg.h"
#include "sp-path.h"
@@ -36,7 +31,6 @@
#include "document-private.h"
#include "document.h"
#include "document-undo.h"
-#include "desktop-handles.h"
#include "verbs.h"
#include "sp-lpe-item.h"
#include "sp-namedview.h"
@@ -47,7 +41,6 @@
// For handling un-continuous paths:
#include "message-stack.h"
#include "inkscape.h"
-#include "desktop.h"
using Inkscape::DocumentUndo;
@@ -64,7 +57,7 @@ LPEBSpline::LPEBSpline(LivePathEffectObject *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),
+ steps(_("Steps with CTRL:"), _("Change number of steps with 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),
@@ -87,7 +80,7 @@ LPEBSpline::LPEBSpline(LivePathEffectObject *lpeobject)
LPEBSpline::~LPEBSpline() {}
-void LPEBSpline::doBeforeEffect (SPLPEItem const* lpeitem)
+void LPEBSpline::doBeforeEffect (SPLPEItem const* /*lpeitem*/)
{
if(!hp.empty()){
hp.clear();
@@ -127,12 +120,8 @@ void LPEBSpline::doEffect(SPCurve *curve)
Geom::PathVector const original_pathv = curve->get_pathvector();
curve->reset();
double radiusHelperNodes = 6.0;
- SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- if (desktop){
- radiusHelperNodes /= SP_ACTIVE_DESKTOP->current_zoom();
- SPNamedView *nv = sp_desktop_namedview(desktop);
- radiusHelperNodes = Inkscape::Util::Quantity::convert(radiusHelperNodes, "px", nv->doc_units->abbr);
- }
+ radiusHelperNodes /= current_zoom;
+ radiusHelperNodes = Inkscape::Util::Quantity::convert(radiusHelperNodes, "px", *defaultUnit);
for (Geom::PathVector::const_iterator path_it = original_pathv.begin();
path_it != original_pathv.end(); ++path_it) {
if (path_it->empty())
@@ -165,16 +154,8 @@ void LPEBSpline::doEffect(SPCurve *curve)
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());
@@ -260,10 +241,7 @@ 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]))) {
@@ -274,12 +252,6 @@ void LPEBSpline::doEffect(SPCurve *curve)
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;
}
@@ -293,7 +265,7 @@ void LPEBSpline::doEffect(SPCurve *curve)
}
if(showHelper){
Geom::PathVector const pathv = curve->get_pathvector();
- hp.push_back(pathv[0]);
+ hp.push_back(pathv[0]);
}
}
@@ -314,7 +286,6 @@ LPEBSpline::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::
{
hp_vec.push_back(hp);
}
-
Gtk::Widget *LPEBSpline::newWidget()
{
// use manage here, because after deletion of Effect object, others might
@@ -332,12 +303,12 @@ Gtk::Widget *LPEBSpline::newWidget()
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));
+ .connect(sigc::mem_fun(*this, &LPEBSpline::toDefaultWeight));
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));
+ .connect(sigc::mem_fun(*this, &LPEBSpline::toMakeCusp));
buttons->pack_start(*makeCusp, true, true, 2);
vbox->pack_start(*buttons, true, true, 2);
}
@@ -381,24 +352,14 @@ Gtk::Widget *LPEBSpline::newWidget()
return dynamic_cast<Gtk::Widget *>(vbox);
}
-void LPEBSpline::toDefaultWeight(Gtk::Widget *widgWeight)
+void LPEBSpline::toDefaultWeight()
{
- weight.param_set_value(defaultStartPower);
changeWeight(defaultStartPower);
- Gtk::HBox * scalarParameter = dynamic_cast<Gtk::HBox *>(widgWeight);
- std::vector< Gtk::Widget* > childList = scalarParameter->get_children();
- Gtk::Entry* entryWidg = dynamic_cast<Gtk::Entry *>(childList[1]);
- entryWidg->set_text("defaultStartPower");
}
-void LPEBSpline::toMakeCusp(Gtk::Widget *widgWeight)
+void LPEBSpline::toMakeCusp()
{
- weight.param_set_value(noPower);
changeWeight(noPower);
- Gtk::HBox * scalarParameter = dynamic_cast<Gtk::HBox *>(widgWeight);
- std::vector< Gtk::Widget* > childList = scalarParameter->get_children();
- Gtk::Entry* entryWidg = dynamic_cast<Gtk::Entry *>(childList[1]);
- entryWidg->set_text("noPower");
}
void LPEBSpline::toWeight()
@@ -408,91 +369,34 @@ void LPEBSpline::toWeight()
void LPEBSpline::changeWeight(double weightValue)
{
- SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- Inkscape::Selection *selection = sp_desktop_selection(desktop);
- GSList *items = (GSList *)selection->itemList();
- SPItem *item = (SPItem *)g_slist_nth(items, 0)->data;
- SPPath *path = SP_PATH(item);
+ SPPath *path = SP_PATH(sp_lpe_item);
SPCurve *curve = path->get_curve_for_edit();
LPEBSpline::doBSplineFromWidget(curve, weightValue);
gchar *str = sp_svg_write_path(curve->get_pathvector());
path->getRepr()->setAttribute("inkscape:original-d", str);
- if (INK_IS_NODE_TOOL(desktop->event_context)) {
- Inkscape::UI::Tools::NodeTool *nt = INK_NODE_TOOL(desktop->event_context);
- nt->desktop->updateNow();
- }
- g_free(str);
- curve->unref();
- desktop->clearWaitingCursor();
- DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_CONTEXT_LPE,
- _("Modified the weight of the BSpline"));
-}
-
-bool LPEBSpline::nodeIsSelected(Geom::Point nodePoint)
-{
- using Geom::X;
- using Geom::Y;
-
- if (points.size() > 0) {
- for (std::vector<Geom::Point>::iterator i = points.begin();
- i != points.end(); ++i) {
- Geom::Point p = *i;
- if (Geom::are_near(p, nodePoint, handleCubicGap)) {
- return true;
- } else {
- }
- }
- }
- return false;
}
void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
{
using Geom::X;
using Geom::Y;
- SPDesktop *desktop = SP_ACTIVE_DESKTOP;
- if (INK_IS_NODE_TOOL(desktop->event_context)) {
- Inkscape::UI::Tools::NodeTool *nt = INK_NODE_TOOL(desktop->event_context);
- Inkscape::UI::ControlPointSelection::Set &selection =
- nt->_selected_nodes->allPoints();
- points.clear();
- std::vector<Geom::Point>::iterator pbegin;
- for (Inkscape::UI::ControlPointSelection::Set::iterator i =
- selection.begin();
- i != selection.end(); ++i) {
- if ((*i)->selected()) {
- Inkscape::UI::Node *n = dynamic_cast<Inkscape::UI::Node *>(*i);
- pbegin = points.begin();
- points.insert(pbegin, desktop->doc2dt(n->position()));
- }
- }
- }
- //bool hasNodesSelected = LPEBspline::hasNodesSelected();
+
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();
- //Recorremos todos los paths a los que queremos aplicar el efecto, hasta el
- //penúltimo
for (Geom::PathVector::const_iterator path_it = original_pathv.begin();
path_it != original_pathv.end(); ++path_it) {
- //Si está vacío...
- if (path_it->empty())
+
+ if (path_it->empty()){
continue;
- //Itreadores
-
- 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
- //Creamos las lineas rectas que unen todos los puntos del trazado y donde se
- //calcularán
- //los puntos clave para los manejadores.
- //Esto hace que la curva BSpline no pierda su condición aunque se trasladen
- //dichos manejadores
+ }
+ 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();
+
SPCurve *nCurve = new SPCurve();
Geom::Point pointAt0(0, 0);
Geom::Point pointAt1(0, 0);
@@ -515,16 +419,8 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
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());
@@ -572,7 +468,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
} else {
if (cubic) {
if (!ignoreCusp || !Geom::are_near((*cubic)[1], pointAt0)) {
- if (nodeIsSelected(pointAt0)) {
+ if (isNodePointSelected(pointAt0)) {
pointAt1 = SBasisIn.valueAt(weightValue);
if (weightValue != noPower) {
pointAt1 =
@@ -585,7 +481,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
pointAt1 = in->first_segment()->initialPoint();
}
if (!ignoreCusp || !Geom::are_near((*cubic)[2], pointAt3)) {
- if (nodeIsSelected(pointAt3)) {
+ if (isNodePointSelected(pointAt3)) {
pointAt2 = SBasisIn.valueAt(1 - weightValue);
if (weightValue != noPower) {
pointAt2 =
@@ -599,14 +495,14 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
}
} else {
if (!ignoreCusp && weightValue != noPower) {
- if (nodeIsSelected(pointAt0)) {
+ if (isNodePointSelected(pointAt0)) {
pointAt1 = SBasisIn.valueAt(weightValue);
pointAt1 =
Geom::Point(pointAt1[X] + handleCubicGap, pointAt1[Y] + handleCubicGap);
} else {
pointAt1 = in->first_segment()->initialPoint();
}
- if (nodeIsSelected(pointAt3)) {
+ if (isNodePointSelected(pointAt3)) {
pointAt2 = SBasisIn.valueAt(weightValue);
pointAt2 =
Geom::Point(pointAt2[X] + handleCubicGap, pointAt2[Y] + handleCubicGap);
@@ -621,14 +517,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
}
in->reset();
delete in;
- //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
nCurve->curveto(pointAt1, pointAt2, pointAt3);
- //aumentamos los valores para el siguiente paso en el bucle
++curve_it1;
++curve_it2;
}
@@ -638,7 +527,6 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weightValue)
} else {
nCurve->move_endpoints(path_it->begin()->initialPoint(), pointAt3);
}
- //y cerramos la curva
if (path_it->closed()) {
nCurve->closepath_current();
}