=== modified file 'src/live_effects/lpe-perspective_path.cpp' --- src/live_effects/lpe-perspective_path.cpp 2013-01-17 20:02:50 +0000 +++ src/live_effects/lpe-perspective_path.cpp 2013-10-12 21:00:57 +0000 @@ -11,11 +11,18 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include +#include +#include //for GTK_RESPONSE* types + #include +#include "document-private.h" + #include "persp3d.h" //#include "transf_mat_3x4.h" #include "document.h" +#include "desktop.h" #include "live_effects/lpe-perspective_path.h" #include "sp-item-group.h" @@ -40,7 +47,7 @@ }; } // namespace PP - +static Glib::ustring perspectiveID = _("First perspective"); LPEPerspectivePath::LPEPerspectivePath(LivePathEffectObject *lpeobject) : Effect(lpeobject), // initialise your parameters here: @@ -59,9 +66,19 @@ concatenate_before_pwd2 = true; // don't split the path into its subpaths _provides_knotholder_entities = true; - + unapply = false; Persp3D *persp = persp3d_document_first_persp(inkscape_active_document()); + if(persp == 0 ){ + char *msg = _("You need a BOX 3D object"); + Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_INFO, + Gtk::BUTTONS_OK, true); + dialog.run(); + unapply = true; + return; + } + Proj::TransfMat3x4 pmat = persp->perspective_impl->tmat; + pmat = pmat * inkscape_active_desktop()->doc2dt(); pmat.copy_tmat(tmat); } @@ -74,13 +91,56 @@ LPEPerspectivePath::doBeforeEffect (SPLPEItem const* lpeitem) { original_bbox(lpeitem, true); + + if(unapply){ + SP_LPE_ITEM(lpeitem)->removeCurrentPathEffect(false); + return; + } } +void LPEPerspectivePath::refresh(Gtk::Entry* perspective) { + perspectiveID = perspective->get_text(); + Persp3D *first = 0; + Persp3D *persp = 0; + for ( SPObject *child = inkscape_active_document()->getDefs()->firstChild(); child && !persp; child = child->getNext() ) { + if (SP_IS_PERSP3D(child) && first == 0) { + first = SP_PERSP3D(child); + } + if (SP_IS_PERSP3D(child) && strcmp(child->getId(), const_cast(perspectiveID.c_str())) == 0) { + persp = SP_PERSP3D(child); + break; + } + } + if(first == 0 ){ + char *msg = _("You need a BOX 3D object"); + Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_INFO, + Gtk::BUTTONS_OK, true); + dialog.run(); + return; + } + if(persp == 0){ + persp = first; + char *msg = _("First perspective selected"); + Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_INFO, + Gtk::BUTTONS_OK, true); + dialog.run(); + perspectiveID = _("First perspective"); + }else{ + char *msg = _("Perspective changed"); + Gtk::MessageDialog dialog(msg, false, Gtk::MESSAGE_INFO, + Gtk::BUTTONS_OK, true); + dialog.run(); + } + Proj::TransfMat3x4 pmat = persp->perspective_impl->tmat; + pmat = pmat * inkscape_active_desktop()->doc2dt(); + pmat.copy_tmat(tmat); +}; + Geom::Piecewise > LPEPerspectivePath::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) { using namespace Geom; - + Piecewise > path_a_pw = pwd2_in; // FIXME: the minus sign is there because the SVG coordinate system goes down; @@ -131,6 +191,7 @@ + preimage[2] * tmat[j][2] + tmat[j][3]; } + D2 > result(divide(res[0],res[2], 3), divide(res[1],res[2], 3)); @@ -139,6 +200,50 @@ return output; } + +Gtk::Widget * +LPEPerspectivePath::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()) ); + + vbox->set_border_width(5); + std::vector::iterator it = param_vector.begin(); + while (it != param_vector.end()) { + if ((*it)->widget_is_visible) { + Parameter * param = *it; + Gtk::Widget * widg = dynamic_cast(param->param_newWidget()); + Glib::ustring * tip = param->param_getTooltip(); + if (widg) { + vbox->pack_start(*widg, true, true, 2); + if (tip) { + widg->set_tooltip_text(*tip); + } else { + widg->set_tooltip_text(""); + widg->set_has_tooltip(false); + } + } + } + + ++it; + } + Gtk::Label* labelPerspective = Gtk::manage(new Gtk::Label("Perspective ID:", 0., 0.)); + Gtk::Widget* labelPerspectiveWidget = dynamic_cast(labelPerspective); + Gtk::Entry* perspective = Gtk::manage(new Gtk::Entry()); + perspective->set_text(perspectiveID); + Gtk::Widget* perspectiveIDWidget = dynamic_cast(perspective); + perspectiveIDWidget->set_tooltip_text("Set the perspective ID to apply"); + vbox->pack_start(*labelPerspectiveWidget, Gtk::PACK_SHRINK,6); + vbox->pack_start(*perspectiveIDWidget, Gtk::PACK_SHRINK,6); + Gtk::Button* apply3D = Gtk::manage(new Gtk::Button(Glib::ustring(_("Refresh perspective")))); + apply3D->set_alignment(0.0, 0.5); + apply3D->signal_clicked().connect(sigc::bind(sigc::mem_fun (*this,&LPEPerspectivePath::refresh),perspective)); + Gtk::Widget* apply3DWidget = dynamic_cast(apply3D); + apply3DWidget->set_tooltip_text("Refresh perspective"); + vbox->pack_start(*apply3DWidget, true, true,2); + return dynamic_cast(vbox); +} + void LPEPerspectivePath::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) { KnotHolderEntity *e = new PP::KnotHolderEntityOffset(this); e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, === modified file 'src/live_effects/lpe-perspective_path.h' --- src/live_effects/lpe-perspective_path.h 2013-01-17 20:02:50 +0000 +++ src/live_effects/lpe-perspective_path.h 2013-10-12 21:00:41 +0000 @@ -16,6 +16,7 @@ #include "live_effects/effect.h" #include "live_effects/parameter/parameter.h" #include "live_effects/parameter/bool.h" +#include "live_effects/parameter/text.h" #include "live_effects/lpegroupbbox.h" #include @@ -33,11 +34,14 @@ public: LPEPerspectivePath(LivePathEffectObject *lpeobject); virtual ~LPEPerspectivePath(); - + virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); + virtual void refresh(Gtk::Entry* perspective); + + virtual Gtk::Widget * newWidget(); /* the knotholder entity classes must be declared friends */ friend class PP::KnotHolderEntityOffset; void addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item); @@ -52,6 +56,7 @@ BoolParam uses_plane_xy; // there are all kinds of parameters. Check the /live_effects/parameter directory which types exist! + bool unapply; Geom::Point orig; LPEPerspectivePath(const LPEPerspectivePath&);