diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-02-15 18:29:48 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-02-15 18:29:48 +0000 |
| commit | 99fb2239028e72f8773bff39e43f7af33b4252d4 (patch) | |
| tree | 23e96adea9f08b37f066559b28aac842cb230879 /src/live_effects | |
| parent | update to trunk (diff) | |
| download | inkscape-99fb2239028e72f8773bff39e43f7af33b4252d4.tar.gz inkscape-99fb2239028e72f8773bff39e43f7af33b4252d4.zip | |
first steps
(bzr r13645.1.9)
Diffstat (limited to 'src/live_effects')
| -rw-r--r-- | src/live_effects/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.cpp | 54 | ||||
| -rw-r--r-- | src/live_effects/lpe-fillet-chamfer.h | 18 | ||||
| -rw-r--r-- | src/live_effects/parameter/Makefile_insert | 4 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.cpp | 51 | ||||
| -rw-r--r-- | src/live_effects/parameter/array.h | 43 | ||||
| -rw-r--r-- | src/live_effects/parameter/pointwise.cpp | 104 | ||||
| -rw-r--r-- | src/live_effects/parameter/pointwise.h | 88 |
8 files changed, 110 insertions, 256 deletions
diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index e171e99e3..6b004e1df 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -63,7 +63,7 @@ set(live_effects_SRC parameter/path-reference.cpp parameter/point.cpp parameter/powerstrokepointarray.cpp - parameter/pointwise.cpp + parameter/satellitepairarray.cpp parameter/random.cpp parameter/text.cpp paramter/transformedpoint.cpp @@ -140,7 +140,7 @@ set(live_effects_SRC parameter/originalpatharray.h parameter/point.h parameter/powerstrokepointarray.h - parameter/pointwise.h + parameter/satellitepairarray.h parameter/random.h parameter/text.h parameter/togglebutton.h diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index f4eb4f46e..884e51ffd 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -14,20 +14,28 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/parameter/pointwise.h" +#include "live_effects/lpe-fillet-chamfer.h" +#include <sp-shape.h> +#include <2geom/pointwise.h> +#include <2geom/satellite.h> +#include <2geom/satellite-enum.h> +#include "helper/geom-nodetype.h" +#include "helper/geom.h" +#include "display/curve.h" +#include <vector> // TODO due to internal breakage in glibmm headers, this must be last: #include <glibmm/i18n.h> -using namespace Geom; + namespace Inkscape { namespace LivePathEffect { LPEFilletChamfer::LPEFilletChamfer(LivePathEffectObject *lpeobject) : Effect(lpeobject), - pointwise_values(_("Fillet point"), _("Fillet point"), "pointwise_values", &wr, this) + satellitepairarrayparam_values(_("Fillet point"), _("Fillet point"), "satellitepairarrayparam_values", &wr, this) { - registerParameter(&pointwise_values); + registerParameter(&satellitepairarrayparam_values); } LPEFilletChamfer::~LPEFilletChamfer() {} @@ -35,12 +43,17 @@ LPEFilletChamfer::~LPEFilletChamfer() {} void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) { - SPShape * shape = dynamic_cast<SPshape *>(lpeItem); + SPLPEItem * splpeitem = const_cast<SPLPEItem *>(lpeItem); + SPShape * shape = dynamic_cast<SPShape *>(splpeitem); if (shape) { - std::vector<std::pair<int,GeomSatellite> pointwise; - PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->gerCurve->get_pathvector()); - //Piecewise<D2<SBasis> > pwd2_in = paths_to_pw(original_pathv); - for (PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { + Geom::PathVector const &original_pathv = pathv_to_linear_and_cubic_beziers(shape->getCurve()->get_pathvector()); + std::vector<std::pair<int,Geom::Satellite> > satellites; + Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_in = paths_to_pw(original_pathv); + pwd2_in = remove_short_cuts(pwd2_in, .01); + Geom::Piecewise<Geom::D2<Geom::SBasis> > der = derivative(pwd2_in); + Geom::Piecewise<Geom::D2<Geom::SBasis> > n = rot90(unitVector(der)); + satellitepairarrayparam_values.set_pwd2(pwd2_in, n); + for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { if (path_it->empty()) continue; @@ -61,16 +74,15 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } int counter = 0; while (curve_it1 != curve_endit) { - Geom::Saltellite sat(FILLET, true, true, false, false, false, 0, 0.2); - std::pair<std::size_t, std::size_t> positions = pointwise_values.get_positions(counter, original_pathv); + Geom::Satellite satellite(Geom::FILLET, true, true, false, false, 0.0, 0.2); Geom::NodeType nodetype; - if (positions.second == 0) { - nodetype = NODE_NONE; - } else { + if(counter!=0){ nodetype = get_nodetype((*path_it)[counter - 1], *curve_it1); + } else { + nodetype = Geom::NODE_NONE; } - if (nodetype == NODE_CUSP) { - pointwise.push_back(std::pair<counter,sat>); + if (nodetype == Geom::NODE_CUSP) { + satellites.push_back(std::make_pair(counter, satellite)); } ++curve_it1; if (curve_it2 != curve_endit) { @@ -79,7 +91,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) counter++; } } - pointwise_values.param_set_and_write_new_value(pointwise); + satellitepairarrayparam_values.param_set_and_write_new_value(satellites); } else { g_warning("LPE Fillet/Chamfer can only be applied to shapes (not groups)."); SPLPEItem * item = const_cast<SPLPEItem*>(lpeItem); @@ -87,6 +99,14 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) } } +void +LPEFilletChamfer::adjustForNewPath(std::vector<Geom::Path> const &path_in) +{ + if (!path_in.empty()) { + //fillet_chamfer_values.recalculate_controlpoints_for_new_pwd2(pathv_to_linear_and_cubic_beziers(path_in)[0].toPwSb()); + } +} + }; //namespace LivePathEffect }; /* namespace Inkscape */ diff --git a/src/live_effects/lpe-fillet-chamfer.h b/src/live_effects/lpe-fillet-chamfer.h index f4462d154..08000c0a5 100644 --- a/src/live_effects/lpe-fillet-chamfer.h +++ b/src/live_effects/lpe-fillet-chamfer.h @@ -15,19 +15,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#if defined(GLIBMM_DISABLE_DEPRECATED) && defined(HAVE_GLIBMM_THREADS_H) -# include <glibmm/threads.h> -#endif - -#include "live_effects/parameter/enum.h" -#include "live_effects/parameter/bool.h" -#include "live_effects/parameter/unit.h" - -#include "live_effects/parameter/pointwise.h" +#include "2geom/pointwise.h" +#include "live_effects/parameter/satellitepairarray.h" #include "live_effects/effect.h" namespace Inkscape { @@ -40,8 +29,9 @@ public: virtual ~LPEFilletChamfer(); virtual void doOnApply(SPLPEItem const *lpeItem); + virtual void adjustForNewPath(std::vector<Geom::Path> const &path_in); - PointwiseArrayParam pointwise_values; + SatellitePairArrayParam satellitepairarrayparam_values; private: diff --git a/src/live_effects/parameter/Makefile_insert b/src/live_effects/parameter/Makefile_insert index d78b1e22f..33c6b0673 100644 --- a/src/live_effects/parameter/Makefile_insert +++ b/src/live_effects/parameter/Makefile_insert @@ -26,8 +26,8 @@ ink_common_sources += \ live_effects/parameter/powerstrokepointarray.h \ live_effects/parameter/filletchamferpointarray.cpp \ live_effects/parameter/filletchamferpointarray.h \ - live_effects/parameter/pointwise.cpp \ - live_effects/parameter/pointwise.h \ + live_effects/parameter/satellitepairarray.cpp \ + live_effects/parameter/satellitepairarray.h \ live_effects/parameter/text.cpp \ live_effects/parameter/text.h \ live_effects/parameter/transformedpoint.cpp \ diff --git a/src/live_effects/parameter/array.cpp b/src/live_effects/parameter/array.cpp index bd2bf1870..d17f28c4f 100644 --- a/src/live_effects/parameter/array.cpp +++ b/src/live_effects/parameter/array.cpp @@ -6,8 +6,7 @@ #include "live_effects/parameter/array.h" -#include "svg/svg.h" -#include "svg/stringstream.h" +#include "helper-fns.h" #include <2geom/coord.h> #include <2geom/point.h> @@ -48,37 +47,47 @@ ArrayParam<Geom::Point>::readsvg(const gchar * str) } return Geom::Point(Geom::infinity(),Geom::infinity()); } -void -sp_svg_satellite_read_d(gchar const *str, satellite *sat){ - gchar ** strarray = g_strsplit(str, "*", 0); - if(strarray.size() != 6){ +//TODO: move maybe to svg-lenght.cpp +unsigned int +sp_svg_satellite_read_d(gchar const *str, Geom::Satellite *sat){ + if (!str) { + return 0; + } + gchar ** strarray = g_strsplit(str, " * ", 0); + if(strarray[6] && !strarray[7]){ + std::map< gchar const *, Geom::SatelliteType> gts = sat->GcharMapToSatelliteType; + sat->setSatelliteType(gts[strarray[0]]); + sat->setIsTime(helperfns_read_bool(strarray[1], true)); + sat->setActive(helperfns_read_bool(strarray[2], true)); + sat->setHasMirror(helperfns_read_bool(strarray[3], false)); + sat->setHidden(helperfns_read_bool(strarray[4], false)); + double time,size; + sp_svg_number_read_d(strarray[5], &time); + sp_svg_number_read_d(strarray[6], &size); + sat->setTime(time); + sat->setSize(size); g_strfreev (strarray); - return NULL; + return 1; } - sat->setSatelliteType(SatelliteTypeMap[strarray[0]]); - sat->setActive(helperfns_read_bool(strarray[1], true)); - sat->sethasMirror(helperfns_read_bool(strarray[2], false)); - sat->setHidden(helperfns_read_bool(strarray[3], false)); - sat->setHidden(helperfns_read_bool(strarray[3], false)); - sat->setTime(sp_svg_number_read_d(strarray[4], 0.0)); - sat->setSize(sp_svg_number_read_d(strarray[5], 0.0)); g_strfreev (strarray); + return 0; } template <> -std::pair<int, satellite> -ArrayParam<Geom::Point>::readsvg(const gchar * str) +std::pair<int, Geom::Satellite> +ArrayParam<std::pair<int, Geom::Satellite> >::readsvg(const gchar * str) { gchar ** strarray = g_strsplit(str, ",", 2); - int index; - Geom::satellite sat = NULL; - unsigned int success = sp_svg_number_read_d(strarray[0], &index); + double index; + std::pair<int, Geom::Satellite> result; + unsigned int success = (int)sp_svg_number_read_d(strarray[0], &index); + Geom::Satellite sat; success += sp_svg_satellite_read_d(strarray[1], &sat); g_strfreev (strarray); if (success == 2) { - return std::pair<index, sat>; + return std::make_pair(index, sat); } - return std::pair<Geom::infinity(),NULL>; + return std::make_pair((int)Geom::infinity(),sat); } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/array.h b/src/live_effects/parameter/array.h index b93c7a617..9f26ed3e6 100644 --- a/src/live_effects/parameter/array.h +++ b/src/live_effects/parameter/array.h @@ -15,6 +15,9 @@ #include "live_effects/parameter/parameter.h" +#include <2geom/satellite.h> +#include <2geom/satellite-enum.h> +#include <2geom/pointwise.h> #include "svg/svg.h" #include "svg/stringstream.h" @@ -93,16 +96,40 @@ protected: // separate items with pipe symbol str << " | "; } - std::pair<int,Geom::satellite> pointwiseElement = dynamic_cast<std::pair<int,Geom::satellite> ><(_vector[i]); - if(pointwiseElement){ - str << vector[i].first; - str << " , "; - str << vector[i].second; - } else { - str << vector[i]; - } + writesvgData(str,vector[i]); } } + + void writesvgData(SVGOStringStream &str, float const &nVector) const { + str << nVector; + } + + void writesvgData(SVGOStringStream &str, double const &nVector) const { + str << nVector; + } + + void writesvgData(SVGOStringStream &str, Geom::Point const &nVector) const { + str << nVector; + } + + void writesvgData(SVGOStringStream &str, std::pair<int, Geom::Satellite> const &nVector) const { + str << nVector.first; + str << " , "; + std::map<Geom::SatelliteType, gchar const *> stg = nVector.second.SatelliteTypeToGcharMap; + str << stg[nVector.second.satellitetype()]; + str << " * "; + str << nVector.second.isTime(); + str << " * "; + str << nVector.second.active(); + str << " * "; + str << nVector.second.hasMirror(); + str << " * "; + str << nVector.second.hidden(); + str << " * "; + str << nVector.second.size(); + str << " * "; + str <<nVector.second.time(); + } StorageType readsvg(const gchar * str); diff --git a/src/live_effects/parameter/pointwise.cpp b/src/live_effects/parameter/pointwise.cpp deleted file mode 100644 index ec83eb6c7..000000000 --- a/src/live_effects/parameter/pointwise.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) Jabiertxo Arraiza Cenoz <jabier.arraiza@marker.es> - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "knotholder.h" - -// TODO due to internal breakage in glibmm headers, -// this has to be included last. -#include <glibmm/i18n.h> - - -using namespace Geom; - -namespace Inkscape { - -namespace LivePathEffect { - -PointwiseParam::PointwiseParam( - const Glib::ustring &label, const Glib::ustring &tip, - const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, - Effect *effect) - : ArrayParam<Pointwise>(label, tip, key, wr, effect, 0) -{ - knot_shape = SP_KNOT_SHAPE_DIAMOND; - knot_mode = SP_KNOT_MODE_XOR; - knot_color = 0x00ff0000; -} - -PointwiseParam::~PointwiseParam() {} - -Gtk::Widget *PointwiseParam::param_newWidget() -{ - return NULL; -} - -void PointwiseParam::set_oncanvas_looks(SPKnotShapeType shape, - SPKnotModeType mode, - guint32 color) -{ - knot_shape = shape; - knot_mode = mode; - knot_color = color; -} - -PointwiseParamKnotHolderEntity:: -PointwiseParamKnotHolderEntity( - PointwiseParam *p) - : _pparam(p) {} - -void PointwiseParamKnotHolderEntity::knot_set(Point const &p, - Point const &/*origin*/, - guint state) -{ - Geom::Point const s = snap_knot_position(p, state); - _pparam->_vector.at(_index).second.setPosition(s,_pparam->_pointwise.pwd2[_pparam->_vector.at(_index).first]); - sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false); -} - -Point PointwiseParamKnotHolderEntity::knot_get() const -{ - Geom::Point const canvas_point = _pparam->_vector.at(_index).second.getPosition(_pparam->_pointwise.pwd2[_pparam->_vector.at(_index).first]); - _pparam->updateCanvasIndicators(); - return canvas_point; -} - - -void PointwiseParam::addKnotHolderEntities(KnotHolder *knotholder, - SPDesktop *desktop, - SPItem *item) -{ - for (unsigned int i = 0; i < _pointwise.satellites.size(); ++i) { - const gchar *tip; - tip = _("<b>Fillet</b>: <b>Ctrl+Click</b> toggle type, " - "<b>Shift+Click</b> open dialog, " - "<b>Ctrl+Alt+Click</b> reset"); - PointwiseParamKnotHolderEntity *e = - new PointwiseParamKnotHolderEntity(this, i); - e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, _(tip), - knot_shape, knot_mode, knot_color); - knotholder->add(e); - } - updateCanvasIndicators(); -} - -} /* namespace LivePathEffect */ - -} /* namespace Inkscape */ - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/parameter/pointwise.h b/src/live_effects/parameter/pointwise.h deleted file mode 100644 index 59f1b4ff4..000000000 --- a/src/live_effects/parameter/pointwise.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_POINTWISE_H -#define INKSCAPE_LIVEPATHEFFECT_POINTWISE_H - -/* - * Inkscape::LivePathEffectParameters - * Copyright (C) Jabiertxo Arraiza Cenoz <jabier.arraiza@marker.es> - * Special thanks to Johan Engelen for the base of the effect -powerstroke- - * Also to ScislaC for point me to the idea - * Also su_v for his construvtive feedback and time - * To Nathan Hurst for his review and help on refactor - * and finaly to Liam P. White for his big help on coding, that save me a lot of - * hours - * - * - * This parameter act as bridge from pointwise class to serialize it as a LPE - * parameter - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include <glib.h> -#include "knot-holder-entity.h" - -namespace Inkscape { - -namespace LivePathEffect { - -class PointwiseParamKnotHolderEntity; - -class PointwiseParam : public ArrayParam<Geom::Pointwise> { -public: - PointwiseParam(const Glib::ustring &label, - const Glib::ustring &tip, - const Glib::ustring &key, - Inkscape::UI::Widget::Registry *wr, - Effect *effect); - virtual ~PointwiseParam(); - - virtual Gtk::Widget * param_newWidget() { - return NULL; - } - - void set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, - guint32 color); - virtual bool providesKnotHolderEntities() const { - return true; - } - friend class PointwiseParamKnotHolderEntity; - -protected: - - StorageType readsvg(const gchar * str); - -private: - PointwiseParam(const PointwiseParam &); - PointwiseParam &operator=(const PointwiseParam &); - - SPKnotShapeType knot_shape; - SPKnotModeType knot_mode; - guint32 knot_color; -}; - -class PointwiseParamKnotHolderEntity : public KnotHolderEntity { -public: - PointwiseParamKnotHolderEntity(PointwiseParam *p, - unsigned int index); - virtual ~PointwiseParamKnotHolderEntity() {} - - virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, - guint state); - virtual Geom::Point knot_get() const; - - /*Checks whether the index falls within the size of the parameter's vector*/ - bool valid_index(unsigned int index) const { - return (_pparam->_vector.size() > index); - } - ; - -private: - PointwiseParam *_pparam; - unsigned int _index; -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif |
