From: dvlierop2 Date: Wed, 12 Dec 2007 18:50:47 +0000 (+0000) Subject: Toggle snapping for each grid individually X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=00583082bf04dd7fd1729bee6489a97b2b56e4bc;p=inkscape.git Toggle snapping for each grid individually --- diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index e16e1fdf2..b4d27084a 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -395,7 +395,8 @@ CanvasAxonomGrid::readRepr() } if ( (value = repr->attribute("snap_enabled")) ) { - snap_enabled = (strcmp(value,"true") == 0); + g_assert(snapper != NULL); + snapper->setEnabled(strcmp(value,"true") == 0); } for (GSList *l = canvasitems; l != NULL; l = l->next) { @@ -437,7 +438,9 @@ CanvasAxonomGrid::updateWidgets() _wr.setUpdating (true); _rcb_visible.setActive(visible); - _rcb_snap_enabled.setActive(snap_enabled); + if (snapper != NULL) { + _rcb_snap_enabled.setActive(snapper->getEnabled()); + } _rumg.setUnit (gridunit); diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 183b299d1..d4a78f265 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -159,7 +159,7 @@ grid_canvasitem_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i }; CanvasGrid::CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type) - : namelabel("", Gtk::ALIGN_CENTER), visible(true), snap_enabled(true), gridtype(type) + : namelabel("", Gtk::ALIGN_CENTER), visible(true), gridtype(type) { repr = in_repr; doc = in_doc; @@ -336,6 +336,14 @@ CanvasGrid::on_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gc ((CanvasGrid*) data)->onReprAttrChanged(repr, key, oldval, newval, is_interactive); } +bool CanvasGrid::isSnapEnabled() +{ + if (snapper == NULL) { + return false; + } + + return snapper->getEnabled(); +} // ########################################################## // CanvasXYGrid @@ -644,6 +652,11 @@ CanvasXYGrid::readRepr() if ( (value = repr->attribute("visible")) ) { visible = (strcmp(value,"true") == 0); } + + if ( (value = repr->attribute("snap_enabled")) ) { + g_assert(snapper != NULL); + snapper->setEnabled(strcmp(value,"true") == 0); + } for (GSList *l = canvasitems; l != NULL; l = l->next) { sp_canvas_item_request_update ( SP_CANVAS_ITEM(l->data) ); @@ -685,7 +698,9 @@ CanvasXYGrid::updateWidgets() _wr.setUpdating (true); _rcb_visible.setActive(visible); - _rcb_snap_enabled.setActive(snap_enabled); + if (snapper != NULL) { + _rcb_snap_enabled.setActive(snapper->getEnabled()); + } _rumg.setUnit (gridunit); @@ -906,6 +921,15 @@ void CanvasXYGridSnapper::_addSnappedLine(SnappedConstraints &sc, NR::Point cons sc.grid_lines.push_back(dummy); } +/** + * \return true if this Snapper will snap at least one kind of point. + */ +bool CanvasXYGridSnapper::ThisSnapperMightSnap() const +{ + return _named_view == NULL ? false : (_snap_enabled && _snap_from != 0); +} + + diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index 07e27cb4a..bc21a14aa 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -99,7 +99,7 @@ public: static void on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data); bool isVisible() { return visible; }; - bool isSnapEnabled() { return snap_enabled; }; + bool isSnapEnabled(); protected: CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type); @@ -115,8 +115,7 @@ protected: Inkscape::UI::Widget::RegisteredCheckButton _rcb_visible; bool visible; Inkscape::UI::Widget::RegisteredCheckButton _rcb_snap_enabled; - bool snap_enabled; - + GridType gridtype; private: @@ -173,6 +172,7 @@ class CanvasXYGridSnapper : public LineSnapper { public: CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d); + bool ThisSnapperMightSnap() const; private: LineList _getSnapLines(NR::Point const &p) const; diff --git a/src/guide-snapper.cpp b/src/guide-snapper.cpp index 0d7dffd00..b660bab9d 100644 --- a/src/guide-snapper.cpp +++ b/src/guide-snapper.cpp @@ -44,7 +44,7 @@ Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(NR::Point */ bool Inkscape::GuideSnapper::ThisSnapperMightSnap() const { - return _named_view == NULL ? false : (_enabled && _snap_from != 0 && _named_view->showguides); + return _named_view == NULL ? false : (_snap_enabled && _snap_from != 0 && _named_view->showguides); } void Inkscape::GuideSnapper::_addSnappedLine(SnappedConstraints &sc, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, NR::Point const point_on_line) const diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 58ef71595..84955cf6d 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -411,7 +411,7 @@ void Inkscape::ObjectSnapper::guideSnap(SnappedConstraints &sc, bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const { bool snap_to_something = _snap_to_itempath || _snap_to_itemnode || _snap_to_bboxpath || _snap_to_bboxnode; - return (_enabled && _snap_from != 0 && snap_to_something); + return (_snap_enabled && _snap_from != 0 && snap_to_something); } diff --git a/src/snapper.cpp b/src/snapper.cpp index 6eb4b5204..096a224d1 100644 --- a/src/snapper.cpp +++ b/src/snapper.cpp @@ -22,7 +22,7 @@ Inkscape::Snapper::PointType const Inkscape::Snapper::SNAPPOINT_GUIDE = 0x4; * \param nv Named view. * \param d Snap distance. */ -Inkscape::Snapper::Snapper(SPNamedView const *nv, NR::Coord const d) : _named_view(nv), _enabled(true), _distance(d) +Inkscape::Snapper::Snapper(SPNamedView const *nv, NR::Coord const d) : _named_view(nv), _snap_enabled(true), _distance(d) { g_assert(_named_view != NULL); g_assert(SP_IS_NAMEDVIEW(_named_view)); @@ -76,7 +76,7 @@ bool Inkscape::Snapper::getSnapFrom(PointType t) const void Inkscape::Snapper::setEnabled(bool s) { - _enabled = s; + _snap_enabled = s; } @@ -124,7 +124,7 @@ void Inkscape::Snapper::freeSnap(SnappedConstraints &sc, std::vector &points_to_snap, std::list const &it) const { - if (_enabled == false || getSnapFrom(t) == false) { + if (_snap_enabled == false || getSnapFrom(t) == false) { return; } @@ -180,7 +180,7 @@ void Inkscape::Snapper::constrainedSnap(SnappedConstraints &sc, ConstraintLine const &c, std::list const &it) const { - if (_enabled == false || getSnapFrom(t) == false) { + if (_snap_enabled == false || getSnapFrom(t) == false) { return; } diff --git a/src/snapper.h b/src/snapper.h index c5c111cff..cf2533f22 100644 --- a/src/snapper.h +++ b/src/snapper.h @@ -55,9 +55,10 @@ public: /** * \return true if this Snapper will snap at least one kind of point. */ - virtual bool ThisSnapperMightSnap() const {return (_enabled && _snap_from != 0);} // will likely be overridden by derived classes + virtual bool ThisSnapperMightSnap() const {return (_snap_enabled && _snap_from != 0);} // will likely be overridden by derived classes void setEnabled(bool s); + bool getEnabled() const {return _snap_enabled;} void freeSnap(SnappedConstraints &sc, PointType const &t, @@ -117,7 +118,7 @@ public: protected: SPNamedView const *_named_view; int _snap_from; ///< bitmap of point types that we will snap from - bool _enabled; ///< true if this snapper is enabled, otherwise false + bool _snap_enabled; ///< true if this snapper is enabled, otherwise false private: