diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-03-14 21:28:34 +0000 |
|---|---|---|
| committer | Jabiertxo Arraiza Zenotz <jtx@jtx.marker.es> | 2013-03-14 21:28:34 +0000 |
| commit | d0bebd018087b363bfde91bce46744dfd004549c (patch) | |
| tree | 1b54402913a026e402618cab5595b026f92af4a0 | |
| parent | update to trunk (diff) | |
| download | inkscape-d0bebd018087b363bfde91bce46744dfd004549c.tar.gz inkscape-d0bebd018087b363bfde91bce46744dfd004549c.zip | |
Updating original path
(bzr r11950.1.53)
| -rw-r--r-- | src/live_effects/lpe-bspline.cpp | 208 | ||||
| -rw-r--r-- | src/live_effects/lpe-bspline.h | 6 | ||||
| -rw-r--r-- | src/live_effects/parameter/parameter.cpp | 7 |
3 files changed, 85 insertions, 136 deletions
diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index fcca38e4c..f5dff3abe 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -35,6 +35,11 @@ LPEBSpline::~LPEBSpline() void LPEBSpline::doEffect(SPCurve * curve) { +LPEBSpline::doEffect(curve,NULL) +} +void +LPEBSpline::doEffect(SPCurve * curve,int value) +{ if(curve->get_segment_count() < 2) return; // Make copy of old path as it is changed during processing @@ -91,11 +96,21 @@ LPEBSpline::doEffect(SPCurve * curve) cubic = dynamic_cast<Geom::CubicBezier const*>(&*curve_it1); if(cubic){ SBasisIn = in->first_segment()->toSBasis(); - pointAt1 = SBasisIn.valueAt(Geom::nearest_point((*cubic)[1],*in->first_segment())); - pointAt2 = SBasisIn.valueAt(Geom::nearest_point((*cubic)[2],*in->first_segment())); + if(value){ + pointAt1 = SBasisIn.valueAt(value); + pointAt2 = SBasisIn.valueAt(1-value); + }else{ + pointAt1 = SBasisIn.valueAt(Geom::nearest_point((*cubic)[1],*in->first_segment())); + pointAt2 = SBasisIn.valueAt(Geom::nearest_point((*cubic)[2],*in->first_segment())); + } }else{ - pointAt1 = in->first_segment()->initialPoint(); - pointAt2 = in->first_segment()->finalPoint(); + if(value){ + pointAt1 = SBasisIn.valueAt(value); + pointAt2 = SBasisIn.valueAt(1-value); + }else{ + pointAt1 = in->first_segment()->initialPoint(); + pointAt2 = in->first_segment()->finalPoint(); + } } in->reset(); delete in; @@ -107,12 +122,22 @@ LPEBSpline::doEffect(SPCurve * curve) cubic = dynamic_cast<Geom::CubicBezier const*>(&*curve_it2); if(cubic){ SBasisOut = out->first_segment()->toSBasis(); - nextPointAt1 = SBasisOut.valueAt(Geom::nearest_point((*cubic)[1],*out->first_segment())); - nextPointAt2 = SBasisOut.valueAt(Geom::nearest_point((*cubic)[2],*out->first_segment()));; + if(value){ + nextPointAt1 = SBasisIn.valueAt(value); + nextPointAt2 = SBasisIn.valueAt(1-value); + }else{ + nextPointAt1 = SBasisOut.valueAt(Geom::nearest_point((*cubic)[1],*out->first_segment())); + nextPointAt2 = SBasisOut.valueAt(Geom::nearest_point((*cubic)[2],*out->first_segment()));; + ] nextPointAt3 = (*cubic)[3]; }else{ - nextPointAt1 = out->first_segment()->initialPoint(); - nextPointAt2 = out->first_segment()->finalPoint(); + if(value){ + nextPointAt1 = SBasisIn.valueAt(value); + nextPointAt2 = SBasisIn.valueAt(1-value); + }else{ + nextPointAt1 = out->first_segment()->initialPoint(); + nextPointAt2 = out->first_segment()->finalPoint(); + } nextPointAt3 = out->first_segment()->finalPoint(); } out->reset(); @@ -133,8 +158,13 @@ LPEBSpline::doEffect(SPCurve * curve) //Y este hará de final de curva node = SBasisHelper.valueAt(0.5); SPCurve *curveHelper = new SPCurve(); - curveHelper->moveto(previousNode); - curveHelper->curveto(pointAt1, pointAt2, node); + if(value){ + curveHelper->moveto(*in->first_segment()->initialPoint()); + curveHelper->curveto(pointAt1, pointAt2, *in->first_segment()->finalPoint()); + }else{ + curveHelper->moveto(previousNode); + curveHelper->curveto(pointAt1, pointAt2, node); + } //añadimos la curva generada a la curva pricipal nCurve->append_continuous(curveHelper, 0.0625); curveHelper->reset(); @@ -181,7 +211,10 @@ LPEBSpline::doEffect(SPCurve * curve) lineHelper->reset(); delete lineHelper; //Guardamos el principio de la curva - startNode = SBasisHelper.valueAt(0.5); + if(value) + startNode = path_it->begin()->initialPoint(); + else + startNode = SBasisHelper.valueAt(0.5); curveHelper->curveto(nextPointAt1, nextPointAt2, startNode); nCurve->append_continuous(curveHelper, 0.0625); nCurve->move_endpoints(startNode,startNode); @@ -208,132 +241,37 @@ LPEBSpline::doEffect(SPCurve * curve) } } -std::vector<Geom::Path> -LPEBSpline::doEffect_path (std::vector<Geom::Path> const &path_in) +void +LPEBSpline::updateAllHandles(int value) { - Geom::PathVector const original_pathv = path_in; - SPCurve *curve = new SPCurve(); - //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()) - 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 - SPCurve *nCurve = new SPCurve(); - Geom::Point previousNode(0,0); - Geom::Point node(0,0); - Geom::Point pointAt0(0,0); - Geom::Point pointAt1(0,0); - Geom::Point pointAt2(0,0); - Geom::Point pointAt3(0,0); - double pos1 = 0; - double pos2 = 0; - Geom::Point nextPointAt1(0,0); - Geom::Point nextPointAt2(0,0); - Geom::Point nextPointAt3(0,0); - Geom::D2< Geom::SBasis > SBasisIn; - Geom::D2< Geom::SBasis > SBasisOut; - Geom::D2< Geom::SBasis > SBasisHelper; - Geom::CubicBezier const *cubic = NULL; - 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(); - } - } - //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 - - //Recorremos todos los segmentos menos el último - while ( curve_it2 != 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()); - cubic = dynamic_cast<Geom::CubicBezier const*>(&*curve_it1); - if(cubic){ - SBasisIn = in->first_segment()->toSBasis(); - pointAt0 = in->first_segment()->initialPoint(); - pos1 = unify_weights/100; - pos2 = 1-unify_weights/100; - pointAt1 = SBasisIn.valueAt(pos1); - pointAt2 = SBasisIn.valueAt(pos2); - pointAt3 = in->first_segment()->finalPoint(); - }else{ - pointAt0 = in->first_segment()->initialPoint(); - pointAt1 = in->first_segment()->initialPoint(); - pointAt2 = in->first_segment()->finalPoint(); - pointAt3 = in->first_segment()->finalPoint(); - } - in->reset(); - delete in; - //Y hacemos lo propio con el path de salida - //nextPointAt0 = curveOut.valueAt(0); - SPCurve * out = new SPCurve(); - out->moveto(curve_it2->initialPoint()); - out->lineto(curve_it2->finalPoint()); - cubic = dynamic_cast<Geom::CubicBezier const*>(&*curve_it2); - if(cubic){ - SBasisOut = out->first_segment()->toSBasis(); - pos1 = unify_weights/100; - pos2 = 1-unify_weights/100; - nextPointAt1 = SBasisOut.valueAt(pos1); - nextPointAt2 = SBasisOut.valueAt(pos2); - nextPointAt3 = (*cubic)[3]; - }else{ - nextPointAt1 = out->first_segment()->initialPoint(); - nextPointAt2 = out->first_segment()->finalPoint(); - nextPointAt3 = out->first_segment()->finalPoint(); - } - out->reset(); - delete out; - //Y este hará de final de curva - SPCurve *curveHelper = new SPCurve(); - curveHelper->moveto(pointAt0); - curveHelper->curveto(pointAt1, pointAt2, pointAt3); - //añadimos la curva generada a la curva pricipal - nCurve->append_continuous(curveHelper, 0.0625); - curveHelper->reset(); - delete curveHelper; - //aumentamos los valores para el siguiente paso en el bucle - ++curve_it1; - ++curve_it2; - } - //Aberiguamos la ultima parte de la curva correspondiente al último segmento - SPCurve *curveHelper = new SPCurve(); - curveHelper->moveto(node); - //Si está cerrada la curva, la cerramos sobre el valor guardado previamente - //Si no finalizamos en el punto final - Geom::Point startNode(0,0); - startNode = path_it->begin()->initialPoint(); - curveHelper->curveto(nextPointAt1, nextPointAt2, nextPointAt3); - nCurve->append_continuous(curveHelper, 0.0625); - nCurve->move_endpoints(startNode,nextPointAt3); - curveHelper->reset(); - delete curveHelper; - //y cerramos la curva - if (path_it->closed()) { - nCurve->closepath_current(); - } - curve->append(nCurve,false); - nCurve->reset(); - delete nCurve; + SPDesktop *desktop = inkscape_active_desktop(); // TODO: Is there a better method to find the item's desktop? + Inkscape::Selection *selection = sp_desktop_selection(desktop); + for (GSList *items = (GSList *) selection->itemList(); + items != NULL; + items = items->next) { + if (SP_IS_LPE_ITEM(items->data) && sp_lpe_item_has_path_effect(items->data)){ + PathEffectList effect_list = sp_lpe_item_get_effect_list(SP_LPE_ITEM(_path)); + lpe_bsp = dynamic_cast<LivePathEffect::LPEBSpline*>( effect_list.front()->lpeobject->get_lpe()); + if(lpe_bsp) + LPEBSpline::updateHandles((SPItem *) items->data,value); + } +} +void +LPEBSpline::updateHandles(SPItem * item,int value){ + + Inkscape::XML::Node *newitem = item->getRepr(); + Inkscape::XML::Node *path = sp_repr_lookup_child(newitem,"svg:path", -1); //unlimited search depth + if ( path != NULL ){ + gchar const *svgd = path->attribute("d"); } - return curve->get_pathvector(); + + SPCurve *original = new SPCurve(); + original = (SPPath *)item->original_curve(); + LPEBSpline::doEffect(original,value); + gchar *str = sp_svg_write_path( original->get_pathvector() ); + g_assert( str != NULL ); + path->setAttribute ("inkscaspe:original-d", str); + item->updateRepr(); } }; //namespace LivePathEffect diff --git a/src/live_effects/lpe-bspline.h b/src/live_effects/lpe-bspline.h index 27c79f040..501b1fdaf 100644 --- a/src/live_effects/lpe-bspline.h +++ b/src/live_effects/lpe-bspline.h @@ -23,6 +23,12 @@ public: virtual LPEPathFlashType pathFlashType() const { return SUPPRESS_FLASH; } virtual void doEffect(SPCurve * curve); + + virtual void doEffect(SPCurve * curve, int value); + + virtual void updateAllHandles(int value); + + virtual void updateHandles(SPItem * item , int value); private: ScalarParam unify_weights; diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 8615721b0..30414842d 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -128,7 +128,12 @@ ScalarParam::param_newWidget() { Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); - + //BSpline + lpe_bsp = dynamic_cast<LivePathEffect::LPEBSpline*>(param_effect->get_lpe()); + if(lpe_bsp){ + lpe_bsp->updateAllHandles(value/100); + } + //BSpline End rsu->setValue(value); rsu->setDigits(digits); rsu->setIncrements(inc_step, inc_page); |
