From ef65b759ee589ea55e59331977b7b7ca20bd4a9e Mon Sep 17 00:00:00 2001 From: dvlierop2 Date: Fri, 3 Aug 2007 19:59:25 +0000 Subject: [PATCH] Rearrange snapping preferences, put distinction between paths and nodes back in, and a bit of refactoring --- src/attributes.cpp | 2 ++ src/attributes.h | 2 ++ src/object-snapper.cpp | 22 ++++++------ src/object-snapper.h | 48 ++++++++++++++------------- src/snap.cpp | 43 ++++++++++++++++++------ src/snap.h | 4 +-- src/sp-namedview.cpp | 17 +++++++++- src/ui/dialog/document-properties.cpp | 31 +++++++++++++---- src/ui/dialog/document-properties.h | 2 +- src/ui/widget/tolerance-slider.cpp | 18 ++++++++-- 10 files changed, 132 insertions(+), 57 deletions(-) diff --git a/src/attributes.cpp b/src/attributes.cpp index 245529e61..ee7ebff69 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -84,6 +84,8 @@ static SPStyleProp const props[] = { {SP_ATTR_INKSCAPE_WINDOW_Y, "inkscape:window-y"}, {SP_ATTR_INKSCAPE_SNAP_BBOX, "inkscape:snap-bbox"}, {SP_ATTR_INKSCAPE_SNAP_NODES, "inkscape:snap-nodes"}, + {SP_ATTR_INKSCAPE_OBJECT_PATHS, "inkscape:object-paths"}, + {SP_ATTR_INKSCAPE_OBJECT_NODES, "inkscape:object-nodes"}, {SP_ATTR_INKSCAPE_CURRENT_LAYER, "inkscape:current-layer"}, {SP_ATTR_INKSCAPE_DOCUMENT_UNITS, "inkscape:document-units"}, {SP_ATTR_INKSCAPE_CONNECTOR_SPACING, "inkscape:connector-spacing"}, diff --git a/src/attributes.h b/src/attributes.h index bb6962304..5eb906320 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -85,6 +85,8 @@ enum SPAttributeEnum { SP_ATTR_INKSCAPE_WINDOW_Y, SP_ATTR_INKSCAPE_SNAP_BBOX, SP_ATTR_INKSCAPE_SNAP_NODES, + SP_ATTR_INKSCAPE_OBJECT_PATHS, + SP_ATTR_INKSCAPE_OBJECT_NODES, SP_ATTR_INKSCAPE_CURRENT_LAYER, SP_ATTR_INKSCAPE_DOCUMENT_UNITS, SP_ATTR_INKSCAPE_CONNECTOR_SPACING, diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 1a50841c4..427b7c507 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -27,8 +27,8 @@ Inkscape::ObjectSnapper::ObjectSnapper(SPNamedView const *nv, NR::Coord const d) - : Snapper(nv, d), _snap_to_itemnodes(true), _snap_to_itempaths(true), - _snap_to_bboxnodes(true), _snap_to_bboxpaths(true), _strict_snapping(true) + : Snapper(nv, d), _snap_to_itemnode(true), _snap_to_itempath(true), + _snap_to_bboxnode(true), _snap_to_bboxpath(true), _strict_snapping(true) { } @@ -84,7 +84,7 @@ void Inkscape::ObjectSnapper::_snapNodes(Inkscape::Snapper::PointType const &t, // Determine the type of bounding box we should snap to SPItem::BBoxType bbox_type = SPItem::GEOMETRIC_BBOX; - if (_snap_to_bboxnodes) { + if (_snap_to_bboxnode) { gchar const *prefs_bbox = prefs_get_string_attribute("tools.select", "bounding_box"); bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX; } @@ -116,7 +116,7 @@ void Inkscape::ObjectSnapper::_snapNodes(Inkscape::Snapper::PointType const &t, std::list points_to_snap_to; //Collect all nodes so we can snap to them - if (_snap_to_itemnodes) { + if (_snap_to_itemnode) { if (!(_strict_snapping && !p_is_a_node)) { if (curve) { int j = 0; @@ -131,7 +131,7 @@ void Inkscape::ObjectSnapper::_snapNodes(Inkscape::Snapper::PointType const &t, } //Collect the bounding box's corners so we can snap to them - if (_snap_to_bboxnodes) { + if (_snap_to_bboxnode) { if (!(_strict_snapping && p_is_a_node)) { NR::Maybe b = sp_item_bbox_desktop(root_item, bbox_type); if (b) { @@ -168,7 +168,7 @@ void Inkscape::ObjectSnapper::_snapPaths(Inkscape::Snapper::PointType const &t, // Determine the type of bounding box we should snap to SPItem::BBoxType bbox_type = SPItem::GEOMETRIC_BBOX; - if (_snap_to_bboxpaths) { + if (_snap_to_bboxpath) { gchar const *prefs_bbox = prefs_get_string_attribute("tools.select", "bounding_box"); bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX; } @@ -193,14 +193,14 @@ void Inkscape::ObjectSnapper::_snapPaths(Inkscape::Snapper::PointType const &t, std::list paths_to_snap_to; //Add the item's path to snap to - if (_snap_to_itempaths) { + if (_snap_to_itempath) { if (!(_strict_snapping && !p_is_a_node)) { paths_to_snap_to.push_back(Path_for_item(root_item, true, true)); } } //Add the item's bounding box to snap to - if (_snap_to_bboxpaths) { + if (_snap_to_bboxpath) { if (!(_strict_snapping && p_is_a_node)) { //This will get ugly... rect -> curve -> bpath NRRect rect; @@ -255,10 +255,10 @@ Inkscape::SnappedPoint Inkscape::ObjectSnapper::_doFreeSnap(Inkscape::Snapper::P SnappedPoint s(p, NR_HUGE); - if (_snap_to_itemnodes || _snap_to_bboxnodes) { + if (_snap_to_itemnode || _snap_to_bboxnode) { _snapNodes(t, s, p, cand); } - if (_snap_to_itempaths || _snap_to_bboxpaths) { + if (_snap_to_itempath || _snap_to_bboxpath) { _snapPaths(t, s, p, cand); } @@ -283,7 +283,7 @@ Inkscape::SnappedPoint Inkscape::ObjectSnapper::_doConstrainedSnap(Inkscape::Sna */ bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const { - bool snap_to_something = _snap_to_itempaths || _snap_to_itemnodes || _snap_to_bboxpaths || _snap_to_bboxnodes; + bool snap_to_something = _snap_to_itempath || _snap_to_itemnode || _snap_to_bboxpath || _snap_to_bboxnode; return (_enabled && _snap_from != 0 && snap_to_something); } diff --git a/src/object-snapper.h b/src/object-snapper.h index 6556b0a24..a0d5f0b65 100644 --- a/src/object-snapper.h +++ b/src/object-snapper.h @@ -27,39 +27,39 @@ class ObjectSnapper : public Snapper public: ObjectSnapper(SPNamedView const *nv, NR::Coord const d); - void setSnapToItemNodes(bool s) { - _snap_to_itemnodes = s; + void setSnapToItemNode(bool s) { + _snap_to_itemnode = s; } - bool getSnapToItemNodes() const { - return _snap_to_itemnodes; + bool getSnapToItemNode() const { + return _snap_to_itemnode; } - void setSnapToItemPaths(bool s) { - _snap_to_itempaths = s; + void setSnapToItemPath(bool s) { + _snap_to_itempath = s; } - bool getSnapToItemPaths() const { - return _snap_to_itempaths; + bool getSnapToItemPath() const { + return _snap_to_itempath; } - void setSnapToBBoxNodes(bool s) { - _snap_to_bboxnodes = s; + void setSnapToBBoxNode(bool s) { + _snap_to_bboxnode = s; } - bool getSnapToBBoxNodes() const { - return _snap_to_bboxnodes; + bool getSnapToBBoxNode() const { + return _snap_to_bboxnode; } - void setSnapToBBoxPaths(bool s) { - _snap_to_bboxpaths = s; + void setSnapToBBoxPath(bool s) { + _snap_to_bboxpath = s; } - bool getSnapToBBoxPaths() const { - return _snap_to_bboxpaths; + bool getSnapToBBoxPath() const { + return _snap_to_bboxpath; } - bool setStrictSnapping(bool enabled) { + void setStrictSnapping(bool enabled) { _strict_snapping = enabled; } @@ -90,13 +90,15 @@ private: NR::Point const &p, std::list const &cand) const; - bool _snap_to_itemnodes; - bool _snap_to_itempaths; - bool _snap_to_bboxnodes; - bool _snap_to_bboxpaths; + bool _snap_to_itemnode; + bool _snap_to_itempath; + bool _snap_to_bboxnode; + bool _snap_to_bboxpath; - //if enabled, then bbox corners will only snap to bboxes, - //and nodes will only snap to nodes and paths + //If enabled, then bbox corners will only snap to bboxes, + //and nodes will only snap to nodes and paths. We will not + //snap bbox corners to nodes, or nodes to bboxes. + //(snapping to grids and guides is not affected by this) bool _strict_snapping; }; diff --git a/src/snap.cpp b/src/snap.cpp index 218cbb029..3ef246447 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -38,7 +38,7 @@ SnapManager::SnapManager(SPNamedView const *v) : object(v, 0), _named_view(v) { - + } @@ -89,18 +89,34 @@ bool SnapManager::SomeSnapperMightSnap() const while (i != s.end() && (*i)->ThisSnapperMightSnap() == false) { i++; } - return (i != s.end()); } +/* + * The snappers have too many parameters to adjust individually. Therefore only + * two snapping modes are presented to the user: snapping bounding box corners (to + * other bounding boxes, grids or guides), and/or snapping nodes (to other nodes, + * paths, grids or guides). To select either of these modes (or both), use the + * methods defined below: setSnapModeBBox() and setSnapModeNode(). + * + * */ + + void SnapManager::setSnapModeBBox(bool enabled) { + //The default values are being set in sp_namedview_set() (in sp-namedview.cpp) guide.setSnapFrom(Inkscape::Snapper::SNAPPOINT_BBOX, enabled); + + for ( GSList const *l = _named_view->grids; l != NULL; l = l->next) { + Inkscape::CanvasGrid *grid = (Inkscape::CanvasGrid*) l->data; + grid->snapper->setSnapFrom(Inkscape::Snapper::SNAPPOINT_BBOX, enabled); + } + object.setSnapFrom(Inkscape::Snapper::SNAPPOINT_BBOX, enabled); - object.setSnapToBBoxNodes(enabled); - object.setSnapToBBoxPaths(enabled); - object.setStrictSnapping(true); + object.setSnapToBBoxNode(enabled); + object.setSnapToBBoxPath(enabled); + object.setStrictSnapping(true); //don't snap bboxes to nodes/paths and vice versa } bool SnapManager::getSnapModeBBox() const @@ -108,17 +124,22 @@ bool SnapManager::getSnapModeBBox() const return guide.getSnapFrom(Inkscape::Snapper::SNAPPOINT_BBOX); } - -void SnapManager::setSnapModeNodes(bool enabled) +void SnapManager::setSnapModeNode(bool enabled) { guide.setSnapFrom(Inkscape::Snapper::SNAPPOINT_NODE, enabled); + + for ( GSList const *l = _named_view->grids; l != NULL; l = l->next) { + Inkscape::CanvasGrid *grid = (Inkscape::CanvasGrid*) l->data; + grid->snapper->setSnapFrom(Inkscape::Snapper::SNAPPOINT_NODE, enabled); + } + object.setSnapFrom(Inkscape::Snapper::SNAPPOINT_NODE, enabled); - object.setSnapToItemNodes(enabled); - object.setSnapToItemPaths(enabled); - object.setStrictSnapping(true); + //object.setSnapToItemNode(enabled); // On second thought, these should be controlled + //object.setSnapToItemPath(enabled); // separately by the snapping prefs dialog + object.setStrictSnapping(true); } -bool SnapManager::getSnapModeNodes() const +bool SnapManager::getSnapModeNode() const { return guide.getSnapFrom(Inkscape::Snapper::SNAPPOINT_NODE); } diff --git a/src/snap.h b/src/snap.h index 527947e10..401fd60ba 100644 --- a/src/snap.h +++ b/src/snap.h @@ -123,9 +123,9 @@ public: SnapperList getGridSnappers() const; void setSnapModeBBox(bool enabled); - void setSnapModeNodes(bool enabled); + void setSnapModeNode(bool enabled); bool getSnapModeBBox() const; - bool getSnapModeNodes() const; + bool getSnapModeNode() const; protected: SPNamedView const *_named_view; diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 7667d07f1..af30b3ed1 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -155,6 +155,8 @@ static void sp_namedview_build(SPObject *object, SPDocument *document, Inkscape: sp_object_read_attr(object, "inkscape:window-y"); sp_object_read_attr(object, "inkscape:snap-bbox"); sp_object_read_attr(object, "inkscape:snap-nodes"); + sp_object_read_attr(object, "inkscape:object-paths"); + sp_object_read_attr(object, "inkscape:object-nodes"); sp_object_read_attr(object, "inkscape:current-layer"); sp_object_read_attr(object, "inkscape:connector-spacing"); @@ -345,7 +347,15 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_INKSCAPE_SNAP_NODES: - nv->snap_manager.setSnapModeNodes(value ? sp_str_to_bool(value) : FALSE); + nv->snap_manager.setSnapModeNode(value ? sp_str_to_bool(value) : TRUE); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_INKSCAPE_OBJECT_PATHS: + nv->snap_manager.object.setSnapToItemPath(value ? sp_str_to_bool(value) : TRUE); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_INKSCAPE_OBJECT_NODES: + nv->snap_manager.object.setSnapToItemNode(value ? sp_str_to_bool(value) : TRUE); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_INKSCAPE_CURRENT_LAYER: @@ -432,6 +442,11 @@ sp_namedview_add_grid(SPNamedView *nv, Inkscape::XML::Node *repr, SPDesktop *des doc = sp_desktop_document(static_cast(nv->views->data)); grid = Inkscape::CanvasGrid::NewGrid(nv, repr, doc, gridtype); nv->grids = g_slist_append(nv->grids, grid); + //Initialize the snapping parameters for the new grid + bool enabled_node = nv->snap_manager.getSnapModeNode(); + bool enabled_bbox = nv->snap_manager.getSnapModeBBox(); + grid->snapper->setSnapFrom(Inkscape::Snapper::SNAPPOINT_NODE, enabled_node); + grid->snapper->setSnapFrom(Inkscape::Snapper::SNAPPOINT_BBOX, enabled_bbox); } if (!desktop) { diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 3a8623852..807d4129f 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -265,24 +265,38 @@ void DocumentProperties::build_snap() { _page_snap.show(); - _rcbsnbb.init (_("Snap bounding _boxes"), + //General options + _rcbsnbb.init (_("Snap bounding _box corners"), _("Snap bounding box corners to grid lines, to guides, and to other bounding boxes"), "inkscape:snap-bbox", _wr); _rcbsnn.init (_("Snap _nodes"), _("Snap nodes to grid lines, to guides, to paths, and to other nodes"), "inkscape:snap-nodes", _wr); - _rsu_sno.init (_("Snap s_ensitivity:"), _("Always snap"), + + //Options for snapping to objects + _rcbsnop.init (_("Snap to _paths"), + _("Snap nodes to object paths"), + "inkscape:object-paths", _wr); + _rcbsnon.init (_("Snap to n_odes"), + _("Snap nodes to object nodes"), + "inkscape:object-nodes", _wr); + _rsu_sno.init (_(" Snap _distance"), _("Snap at any dist_ance"), _("Snapping distance, in screen pixels, for snapping to objects"), _("If set, objects snap to the nearest object, regardless of distance"), "objecttolerance", _wr); - _rsu_sn.init (_("Snap sens_itivity:"), _("Always snap"), + + //Options for snapping to grids + _rsu_sn.init (_(" Snap d_istance"), _("Snap at any distan_ce"), _("Snapping distance, in screen pixels, for snapping to grid"), _("If set, objects snap to the nearest grid line, regardless of distance"), "gridtolerance", _wr); - _rsu_gusn.init (_("Snap sensiti_vity:"), _("Always snap"), + + //Options for snapping to guides + _rsu_gusn.init (_(" Snap di_stance"), _("Snap at any distanc_e"), _("Snapping distance, in screen pixels, for snapping to guides"), _("If set, objects snap to the nearest guide, regardless of distance"), "guidetolerance", _wr); + Gtk::Label *label_g = manage (new Gtk::Label); label_g->set_markup (_("General")); Gtk::Label *label_o = manage (new Gtk::Label); @@ -295,9 +309,12 @@ DocumentProperties::build_snap() Gtk::Widget *const array[] = { label_g, 0, + 0, _rcbsnn._button, 0, _rcbsnbb._button, - 0, _rcbsnn._button, + 0, 0, label_o, 0, + 0, _rcbsnop._button, + 0, _rcbsnon._button, 0, _rsu_sno._vbox, 0, 0, label_gr, 0, @@ -416,7 +433,9 @@ DocumentProperties::update() //-----------------------------------------------------------snap _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox()); - _rcbsnn.setActive (nv->snap_manager.getSnapModeNodes()); + _rcbsnn.setActive (nv->snap_manager.getSnapModeNode()); + _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath()); + _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode()); _rsu_sno.setValue (nv->objecttolerance); _rsu_sn.setValue (nv->gridtolerance); diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h index f405e71a3..d2f8776e4 100644 --- a/src/ui/dialog/document-properties.h +++ b/src/ui/dialog/document-properties.h @@ -73,7 +73,7 @@ protected: RegisteredUnitMenu _rum_gusn; RegisteredColorPicker _rcp_gui, _rcp_hgui; //--------------------------------------------------------------- - RegisteredCheckButton _rcbsnbb, _rcbsnn; + RegisteredCheckButton _rcbsnbb, _rcbsnn, _rcbsnop, _rcbsnon; RegisteredUnitMenu _rumso; ToleranceSlider _rsu_sno, _rsu_sn, _rsu_gusn; RegisteredRadioButtonPair _rrb_pix; diff --git a/src/ui/widget/tolerance-slider.cpp b/src/ui/widget/tolerance-slider.cpp index f9a991c24..92a6f76bb 100644 --- a/src/ui/widget/tolerance-slider.cpp +++ b/src/ui/widget/tolerance-slider.cpp @@ -56,10 +56,22 @@ ToleranceSlider::~ToleranceSlider() void ToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& label2, const Glib::ustring& tip1, const Glib::ustring& tip2, const Glib::ustring& key, Registry& wr) { + // hbox = label + slider + // + // e.g. + // + // snap distance |-------X---| 37 + + // vbox = checkbutton + // + + // hbox + _vbox = new Gtk::VBox; _hbox = manage (new Gtk::HBox); + Gtk::Label *theLabel1 = manage (new Gtk::Label (label1)); theLabel1->set_use_underline(); + theLabel1->set_alignment(0, 0.5); _hbox->add (*theLabel1); _hscale = manage (new Gtk::HScale (1.0, 51, 1.0)); theLabel1->set_mnemonic_widget (*_hscale); @@ -69,15 +81,17 @@ ToleranceSlider::init (const Glib::ustring& label1, const Glib::ustring& label2, _old_val = 10; _hscale->set_value (_old_val); _tt.set_tip (*_hscale, tip1); - _hbox->add (*_hscale); - _vbox->add (*_hbox); + _hbox->add (*_hscale); + Gtk::Label *theLabel2 = manage (new Gtk::Label (label2)); theLabel2->set_use_underline(); _button = manage (new Gtk::CheckButton); _tt.set_tip (*_button, tip2); _button->add (*theLabel2); _button->set_alignment (0.0, 0.5); + _vbox->add (*_button); + _vbox->add (*_hbox); _key = key; _scale_changed_connection = _hscale->signal_value_changed().connect (sigc::mem_fun (*this, &ToleranceSlider::on_scale_changed)); _btn_toggled_connection = _button->signal_toggled().connect (sigc::mem_fun (*this, &ToleranceSlider::on_toggled)); -- 2.30.2