summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJabier Arraiza Cenoz <jabier.arraiza@marker.es>2014-11-15 17:29:41 +0000
committerJabiertxof <jtx@jtx.marker.es>2014-11-15 17:29:41 +0000
commita5333b6abc807176319c96d66cb7111e70f4896f (patch)
tree5d835204a110f9fa328e96919078edf83af69784 /src
parentSix a bug on subpaths pointed by suv (diff)
downloadinkscape-a5333b6abc807176319c96d66cb7111e70f4896f.tar.gz
inkscape-a5333b6abc807176319c96d66cb7111e70f4896f.zip
ignore this commit
(bzr r13682.1.9)
Diffstat (limited to 'src')
-rw-r--r--src/knotholder.cpp6
-rw-r--r--src/live_effects/effect.cpp8
-rw-r--r--src/live_effects/effect.h2
-rw-r--r--src/live_effects/lpe-bendpath.cpp4
-rw-r--r--src/live_effects/lpe-mirror_symmetry.cpp103
-rw-r--r--src/live_effects/lpe-mirror_symmetry.h15
-rw-r--r--src/live_effects/lpegroupbbox.cpp12
-rw-r--r--src/ui/dialog/livepatheffect-editor.cpp35
8 files changed, 171 insertions, 14 deletions
diff --git a/src/knotholder.cpp b/src/knotholder.cpp
index f46daa09e..28f6f5748 100644
--- a/src/knotholder.cpp
+++ b/src/knotholder.cpp
@@ -69,6 +69,12 @@ KnotHolder::KnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFun
}
KnotHolder::~KnotHolder() {
+ if(SP_IS_LPE_ITEM(item)){
+ Inkscape::LivePathEffect::Effect *effect = SP_LPE_ITEM(item)->getCurrentLPE();
+ if(effect){
+ effect->removeHandles();
+ }
+ }
sp_object_unref(item);
for (std::list<KnotHolderEntity *>::iterator i = entity.begin(); i != entity.end(); ++i)
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index eb649db62..9997b1662 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -613,7 +613,7 @@ Effect::registerParameter(Parameter * param)
void
Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
using namespace Inkscape::LivePathEffect;
-
+ knot_holder = knotholder;
// add handles provided by the effect itself
addKnotHolderEntities(knotholder, desktop, item);
@@ -623,6 +623,12 @@ Effect::addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
}
}
+void
+Effect::removeHandles(){
+ if(knot_holder){
+ knot_holder = NULL;
+ }
+}
/**
* Return a vector of PathVectors which contain all canvas indicators for this effect.
* This is the function called by external code to get all canvas indicators (effect and its parameters)
diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h
index 7da76b267..5d715c7f2 100644
--- a/src/live_effects/effect.h
+++ b/src/live_effects/effect.h
@@ -101,6 +101,7 @@ public:
// (but spiro lpe still needs it!)
virtual LPEPathFlashType pathFlashType() const { return DEFAULT; }
void addHandles(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
+ void removeHandles();
std::vector<Geom::PathVector> getCanvasIndicators(SPLPEItem const* lpeitem);
inline bool providesOwnFlashPaths() const {
@@ -160,6 +161,7 @@ protected:
SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them.
Glib::ustring const * defaultUnit; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them.
+ KnotHolder *knot_holder;
double current_zoom;
std::vector<Geom::Point> selectedNodesPoints;
SPCurve * sp_curve;
diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp
index 33171b184..968e12518 100644
--- a/src/live_effects/lpe-bendpath.cpp
+++ b/src/live_effects/lpe-bendpath.cpp
@@ -137,7 +137,9 @@ LPEBendPath::resetDefaults(SPItem const* item)
Geom::Point start(boundingbox_X.min(), (boundingbox_Y.max()+boundingbox_Y.min())/2);
Geom::Point end(boundingbox_X.max(), (boundingbox_Y.max()+boundingbox_Y.min())/2);
-
+ std::cout << start << "start\n";
+ std::cout << start << "end\n";
+ std::cout << boundingbox_X.min() << "boundingbox_X.min\n";
if ( Geom::are_near(start,end) ) {
end += Geom::Point(1.,0.);
}
diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp
index 6fb2bfc73..dc9a94b1b 100644
--- a/src/live_effects/lpe-mirror_symmetry.cpp
+++ b/src/live_effects/lpe-mirror_symmetry.cpp
@@ -24,23 +24,43 @@
#include <2geom/path-intersection.h>
#include <2geom/transforms.h>
#include <2geom/affine.h>
+#include "knot-holder-entity.h"
+#include "knotholder.h"
namespace Inkscape {
namespace LivePathEffect {
+namespace MS {
+
+class KnotHolderEntityCenterMirrorSymmetry : public LPEKnotHolderEntity {
+public:
+ KnotHolderEntityCenterMirrorSymmetry(LPEMirrorSymmetry *effect) : LPEKnotHolderEntity(effect) {};
+ virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
+ virtual Geom::Point knot_get() const;
+};
+
+} // namespace MS
+
LPEMirrorSymmetry::LPEMirrorSymmetry(LivePathEffectObject *lpeobject) :
Effect(lpeobject),
discard_orig_path(_("Discard original path?"), _("Check this to only keep the mirrored part of the path"), "discard_orig_path", &wr, this, false),
fusionPaths(_("Fusioned symetry"), _("Fusion right side whith symm"), "fusionPaths", &wr, this, true),
reverseFusion(_("Reverse fusion"), _("Reverse fusion"), "reverseFusion", &wr, this, false),
- reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0")
+ forceX(_("Force horizontal"), _("Force horizontal"), "forceX", &wr, this, false),
+ forceY(_("Force vertical"), _("Force vertical"), "forceY", &wr, this, false),
+ reflection_line(_("Reflection line:"), _("Line which serves as 'mirror' for the reflection"), "reflection_line", &wr, this, "M0,0 L1,0"),
+ center(_("Center of mirroring (X or Y)"), _("Center of the mirror"), "center", &wr, this, "Adjust the center of mirroring")
{
show_orig_path = true;
registerParameter( dynamic_cast<Parameter *>(&discard_orig_path) );
registerParameter( dynamic_cast<Parameter *>(&fusionPaths) );
registerParameter( dynamic_cast<Parameter *>(&reverseFusion) );
+ registerParameter( dynamic_cast<Parameter *>(&forceX) );
+ registerParameter( dynamic_cast<Parameter *>(&forceY) );
registerParameter( dynamic_cast<Parameter *>(&reflection_line) );
+ registerParameter( dynamic_cast<Parameter *>(&center) );
+
}
LPEMirrorSymmetry::~LPEMirrorSymmetry()
@@ -50,9 +70,36 @@ LPEMirrorSymmetry::~LPEMirrorSymmetry()
void
LPEMirrorSymmetry::doBeforeEffect (SPLPEItem const* lpeitem)
{
+ using namespace Geom;
+
SPLPEItem * item = const_cast<SPLPEItem*>(lpeitem);
std::vector<Geom::Path> mline(reflection_line.get_pathvector());
- lineSeparation.setPoints(mline[0].initialPoint(),mline[0].finalPoint());
+ double dist = distance(mline[0].initialPoint(),mline[0].finalPoint());
+ if( !forceX && !forceY ){
+ center.param_setValue(mline[0].pointAt(0.5));
+ }
+ Point A(0,0);
+ Point B(0,0);
+ if(forceX){
+ A = Geom::Point(center[X]+(dist/2.0),center[Y]);
+ B = Geom::Point(center[X]-(dist/2.0),center[Y]);
+ }
+ if(forceY){
+ A = Geom::Point(center[X],center[Y]+(dist/2.0));
+ B = Geom::Point(center[X],center[Y]-(dist/2.0));
+ }
+ if( forceX || forceY ){
+ lineSeparation.setPoints(A,B);
+ Piecewise<D2<SBasis> > rline = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(A[X], B[X]), Linear(A[Y], B[Y])));
+ reflection_line.set_new_value(rline, true);
+ } else {
+ lineSeparation.setPoints(mline[0].initialPoint(),mline[0].finalPoint());
+ }
+ //Geom::Point const q = lineSeparation.pointAt(0.5)* lpeitem->i2dt_affine().inverse();
+ if(knot_holder){
+ knot_holder->update_knots();
+ }
+ //e->knot_set(q, e->knot->drag_origin * lpeitem->i2dt_affine().inverse(), (guint)1);
item->apply_to_clippath(item);
item->apply_to_mask(item);
}
@@ -200,6 +247,58 @@ LPEMirrorSymmetry::doEffect_path (std::vector<Geom::Path> const & path_in)
return path_out;
}
+void
+LPEMirrorSymmetry::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
+{
+ using namespace Geom;
+
+ PathVector pathv;
+ Geom::Path mlineExpanded;
+ Geom::Point lineStart = lineSeparation.pointAt(-100000.0);
+ Geom::Point lineEnd = lineSeparation.pointAt(100000.0);
+ mlineExpanded.start( lineStart);
+ mlineExpanded.appendNew<Geom::LineSegment>( lineEnd);
+ pathv.push_back(mlineExpanded);
+ hp_vec.push_back(pathv);
+}
+
+void
+LPEMirrorSymmetry::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
+ {
+ KnotHolderEntity *e = new MS::KnotHolderEntityCenterMirrorSymmetry(this);
+ e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN,
+ _("Adjust the center") );
+ knotholder->add(e);
+ }
+
+};
+
+namespace MS {
+
+using namespace Geom;
+
+void
+KnotHolderEntityCenterMirrorSymmetry::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state)
+{
+ LPEMirrorSymmetry* lpe = dynamic_cast<LPEMirrorSymmetry *>(_effect);
+
+ Geom::Point const s = snap_knot_position(p, state);
+
+ lpe->center.param_setValue(s);
+
+ // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
+ sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
+}
+
+Geom::Point
+KnotHolderEntityCenterMirrorSymmetry::knot_get() const
+{
+ LPEMirrorSymmetry const *lpe = dynamic_cast<LPEMirrorSymmetry const*>(_effect);
+ return lpe->center;
+}
+
+} // namespace CR
+
} //namespace LivePathEffect
} /* namespace Inkscape */
diff --git a/src/live_effects/lpe-mirror_symmetry.h b/src/live_effects/lpe-mirror_symmetry.h
index c925f220f..4b2c9aea0 100644
--- a/src/live_effects/lpe-mirror_symmetry.h
+++ b/src/live_effects/lpe-mirror_symmetry.h
@@ -25,6 +25,11 @@
namespace Inkscape {
namespace LivePathEffect {
+namespace MS {
+ // we need a separate namespace to avoid clashes with LPEPerpBisector
+ class KnotHolderEntityCenterMirrorSymmetry;
+}
+
class LPEMirrorSymmetry : public Effect, GroupBBoxEffect{
public:
LPEMirrorSymmetry(LivePathEffectObject *lpeobject);
@@ -38,12 +43,22 @@ public:
virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> const & path_in);
+ /* the knotholder entity classes must be declared friends */
+ friend class MS::KnotHolderEntityCenterMirrorSymmetry;
+ void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item);
+
+protected:
+ virtual void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector<Geom::PathVector> &hp_vec);
+
private:
BoolParam discard_orig_path;
BoolParam fusionPaths;
BoolParam reverseFusion;
+ BoolParam forceX;
+ BoolParam forceY;
PathParam reflection_line;
Geom::Line lineSeparation;
+ PointParam center;
LPEMirrorSymmetry(const LPEMirrorSymmetry&);
LPEMirrorSymmetry& operator=(const LPEMirrorSymmetry&);
diff --git a/src/live_effects/lpegroupbbox.cpp b/src/live_effects/lpegroupbbox.cpp
index 2a1b70a6a..78545e9c5 100644
--- a/src/live_effects/lpegroupbbox.cpp
+++ b/src/live_effects/lpegroupbbox.cpp
@@ -8,6 +8,7 @@
#include "live_effects/lpegroupbbox.h"
#include "sp-item.h"
+#include "sp-item-group.h"
namespace Inkscape {
namespace LivePathEffect {
@@ -34,9 +35,20 @@ void GroupBBoxEffect::original_bbox(SPLPEItem const* lpeitem, bool absolute)
}
Geom::OptRect bbox = lpeitem->geometricBounds(transform);
+ std::cout << bbox->hasZeroArea() << "=AREA\n";
+ if(bbox->hasZeroArea() && SP_IS_GROUP(lpeitem)){
+ bbox = (Geom::OptRect)SP_GROUP(lpeitem)->bbox(transform, SPLPEItem::GEOMETRIC_BBOX);
+ //GSList const *items = sp_item_group_item_list(SPGroup * group);
+ //for ( GSList const *i = items ; i != NULL ; i = i->next ) {
+ // bbox.unionWith(SP_ITEM(i->data)->desktopGeometricBounds());
+ //}
+ }
+ std::cout << bbox->hasZeroArea() << "=AREA222\n";
if (bbox) {
boundingbox_X = (*bbox)[Geom::X];
boundingbox_Y = (*bbox)[Geom::Y];
+ std::cout << boundingbox_X << "=BBOXX\n";
+ std::cout << boundingbox_Y << "=BBOXY\n";
} else {
boundingbox_X = Geom::Interval();
boundingbox_Y = Geom::Interval();
diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp
index eb3857ee7..e9c012ff5 100644
--- a/src/ui/dialog/livepatheffect-editor.cpp
+++ b/src/ui/dialog/livepatheffect-editor.cpp
@@ -292,8 +292,11 @@ LivePathEffectEditor::onSelectionChanged(Inkscape::Selection *sel)
effectlist_store->clear();
current_lpeitem = NULL;
- if ( sel && !sel->isEmpty() ) {
- SPItem *item = sel->singleItem();
+ if ( sel && (sel->isEmpty() || sel->singleItem())) {
+ SPItem * item= SP_ITEM(current_desktop->currentRoot());
+ if(!sel->isEmpty()){
+ item = sel->singleItem();
+ }
if ( item ) {
SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item);
if ( lpeitem ) {
@@ -422,8 +425,11 @@ void
LivePathEffectEditor::onAdd()
{
Inkscape::Selection *sel = _getSelection();
- if ( sel && !sel->isEmpty() ) {
- SPItem *item = sel->singleItem();
+ if ( sel && (sel->isEmpty() || sel->singleItem())) {
+ SPItem * item= SP_ITEM(current_desktop->currentRoot());
+ if(!sel->isEmpty()){
+ item = sel->singleItem();
+ }
if (item) {
if ( dynamic_cast<SPLPEItem *>(item) ) {
// show effectlist dialog
@@ -500,8 +506,11 @@ void
LivePathEffectEditor::onRemove()
{
Inkscape::Selection *sel = _getSelection();
- if ( sel && !sel->isEmpty() ) {
- SPItem *item = sel->singleItem();
+ if ( sel && (sel->isEmpty() || sel->singleItem())) {
+ SPItem * item= SP_ITEM(current_desktop->currentRoot());
+ if(!sel->isEmpty()){
+ item = sel->singleItem();
+ }
SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item);
if ( lpeitem ) {
lpeitem->removeCurrentPathEffect(false);
@@ -518,8 +527,11 @@ LivePathEffectEditor::onRemove()
void LivePathEffectEditor::onUp()
{
Inkscape::Selection *sel = _getSelection();
- if ( sel && !sel->isEmpty() ) {
- SPItem *item = sel->singleItem();
+ if ( sel && (sel->isEmpty() || sel->singleItem())) {
+ SPItem * item= SP_ITEM(current_desktop->currentRoot());
+ if(!sel->isEmpty()){
+ item = sel->singleItem();
+ }
SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item);
if ( lpeitem ) {
lpeitem->upCurrentPathEffect();
@@ -535,8 +547,11 @@ void LivePathEffectEditor::onUp()
void LivePathEffectEditor::onDown()
{
Inkscape::Selection *sel = _getSelection();
- if ( sel && !sel->isEmpty() ) {
- SPItem *item = sel->singleItem();
+ if ( sel && (sel->isEmpty() || sel->singleItem())) {
+ SPItem * item= SP_ITEM(current_desktop->currentRoot());
+ if(!sel->isEmpty()){
+ item = sel->singleItem();
+ }
SPLPEItem *lpeitem = dynamic_cast<SPLPEItem *>(item);
if ( lpeitem ) {
lpeitem->downCurrentPathEffect();