From: dvlierop2 Date: Mon, 5 Nov 2007 21:15:27 +0000 (+0000) Subject: Improve the user interaction for snapping of bounding boxes, and add an new tab in... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4550d1abdb3f428b8cd47c144d2cd112254bfb8e;p=inkscape.git Improve the user interaction for snapping of bounding boxes, and add an new tab in document properties for detailed snapping options --- diff --git a/src/attributes.cpp b/src/attributes.cpp index 5fb4a87a0..f09e9cc36 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -90,6 +90,8 @@ static SPStyleProp const props[] = { {SP_ATTR_INKSCAPE_SNAP_CENTER, "inkscape:snap-center"}, {SP_ATTR_INKSCAPE_OBJECT_PATHS, "inkscape:object-paths"}, {SP_ATTR_INKSCAPE_OBJECT_NODES, "inkscape:object-nodes"}, + {SP_ATTR_INKSCAPE_BBOX_PATHS, "inkscape:bbox-paths"}, + {SP_ATTR_INKSCAPE_BBOX_NODES, "inkscape:bbox-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 6d05361f2..768fd0003 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -91,6 +91,8 @@ enum SPAttributeEnum { SP_ATTR_INKSCAPE_SNAP_CENTER, SP_ATTR_INKSCAPE_OBJECT_PATHS, SP_ATTR_INKSCAPE_OBJECT_NODES, + SP_ATTR_INKSCAPE_BBOX_PATHS, + SP_ATTR_INKSCAPE_BBOX_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 10e0c43d4..67b465d03 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -141,7 +141,6 @@ bool Inkscape::ObjectSnapper::_snapNodes(Inkscape::Snapper::PointType const &t, if (first_point) { _points_to_snap_to->clear(); for (std::vector::const_iterator i = _candidates->begin(); i != _candidates->end(); i++) { - //NR::Matrix i2doc(NR::identity()); SPItem *root_item = *i; if (SP_IS_USE(*i)) { diff --git a/src/object-snapper.h b/src/object-snapper.h index d1a2c94ce..4785ca431 100644 --- a/src/object-snapper.h +++ b/src/object-snapper.h @@ -91,8 +91,8 @@ private: Inkscape::Snapper::PointType const &t, NR::Point const &p, bool const &first_point, - std::vector &points_to_snap, - std::list const &it) const; + std::vector &points_to_snap, + std::list const &it) const; void _doConstrainedSnap(SnappedConstraints &sc, Inkscape::Snapper::PointType const &t, diff --git a/src/seltrans.cpp b/src/seltrans.cpp index b95e70c4a..3650b18b6 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -1057,7 +1057,7 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR:: NR::Coord const bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE; NR::Coord const sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE; NR::Coord const ratio = (bd < sd) ? bb.first : sn.first; - + s[axis] = fabs(ratio) * sign(s[axis]); s[perp] = fabs(s[axis]); } else { @@ -1084,6 +1084,7 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR:: NR::Coord const bd = bb.second ? fabs(bb.first - s[axis]) : NR_HUGE; NR::Coord const sd = sn.second ? fabs(sn.first - s[axis]) : NR_HUGE; s[axis] = (bd < sd) ? bb.first : sn.first; + s[perp] = 1; } diff --git a/src/snap.cpp b/src/snap.cpp index 1a05bdaac..d5ec91f86 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -122,8 +122,8 @@ void SnapManager::setSnapModeBBox(bool enabled) } object.setSnapFrom(Inkscape::Snapper::SNAPPOINT_BBOX, enabled); - object.setSnapToBBoxNode(enabled); - object.setSnapToBBoxPath(enabled); + //object.setSnapToBBoxNode(enabled); // On second thought, these should be controlled + //object.setSnapToBBoxPath(enabled); // separately by the snapping prefs dialog object.setStrictSnapping(true); //don't snap bboxes to nodes/paths and vice versa } @@ -430,18 +430,21 @@ std::pair SnapManager::_snapTransformed( std::vector::const_iterator j = transformed_points.begin(); + // std::cout << std::endl; + for (std::vector::const_iterator i = points.begin(); i != points.end(); i++) { /* Snap it */ Inkscape::SnappedPoint const snapped = constrained ? constrainedSnap(type, *j, i == points.begin(), transformed_points, constraint, ignore) : freeSnap(type, *j, i == points.begin(), transformed_points, ignore); + NR::Point result; + NR::Coord metric; + if (snapped.getDistance() < NR_HUGE) { /* We snapped. Find the transformation that describes where the snapped point has ** ended up, and also the metric for this transformation. */ - NR::Point result; - NR::Coord metric; switch (transformation_type) { case TRANSLATION: result = snapped.getPoint() - *i; @@ -488,9 +491,11 @@ std::pair SnapManager::_snapTransformed( if ((metric < best_metric) || ((metric == best_metric) && snapped.getAtIntersection() == true)) { best_transformation = result; best_metric = metric; - } + // std::cout << "SEL ";; + } //else { std::cout << " ";} } + // std::cout << "P_orig = " << (*i) << " | metric = " << metric << " | distance = " << snapped.getDistance() << " | P_snap = " << snapped.getPoint() << std::endl; j++; } diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index aeaa8dc14..8b9bc008e 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -160,6 +160,8 @@ static void sp_namedview_build(SPObject *object, SPDocument *document, Inkscape: sp_object_read_attr(object, "inkscape:snap-center"); sp_object_read_attr(object, "inkscape:object-paths"); sp_object_read_attr(object, "inkscape:object-nodes"); + sp_object_read_attr(object, "inkscape:bbox-paths"); + sp_object_read_attr(object, "inkscape:bbox-nodes"); sp_object_read_attr(object, "inkscape:current-layer"); sp_object_read_attr(object, "inkscape:connector-spacing"); @@ -377,6 +379,14 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va nv->snap_manager.object.setSnapToItemNode(value ? sp_str_to_bool(value) : FALSE); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_INKSCAPE_BBOX_PATHS: + nv->snap_manager.object.setSnapToBBoxPath(value ? sp_str_to_bool(value) : FALSE); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + case SP_ATTR_INKSCAPE_BBOX_NODES: + nv->snap_manager.object.setSnapToBBoxNode(value ? sp_str_to_bool(value) : FALSE); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; case SP_ATTR_INKSCAPE_CURRENT_LAYER: nv->default_layer_id = value ? g_quark_from_string(value) : 0; object->requestModified(SP_OBJECT_MODIFIED_FLAG); diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index e2dc2c0b9..4f8db942d 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -93,7 +93,7 @@ DocumentProperties::destroy() DocumentProperties::DocumentProperties(Behavior::BehaviorFactory behavior_factory) : Dialog (behavior_factory, "dialogs.documentoptions", SP_VERB_DIALOG_NAMEDVIEW), _page_page(1, 1), _page_guides(1, 1), - _page_snap(1, 1), _page_grids(1, 1), + _page_snap(1, 1), _page_grids(1, 1), _page_snap_dtls(1, 1), _grids_button_new(_("_New"), _("Create new grid.")), _grids_button_remove(_("_Remove"), _("Remove selected grid.")), _prefs_path("dialogs.documentoptions") @@ -106,12 +106,14 @@ DocumentProperties::DocumentProperties(Behavior::BehaviorFactory behavior_factor _notebook.append_page(_page_page, _("Page")); _notebook.append_page(_page_guides, _("Guides")); _notebook.append_page(_page_grids, _("Grids")); - _notebook.append_page(_page_snap, _("Snapping")); + _notebook.append_page(_page_snap, _("Snap")); + _notebook.append_page(_page_snap_dtls, _("Snap details")); build_page(); build_guides(); build_gridspage(); build_snap(); + build_snap_dtls(); _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid)); _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid)); @@ -266,47 +268,56 @@ DocumentProperties::build_snap() { _page_snap.show(); //General options - _rcbsnbb.init (_("Bounding _box corners"), - _("Snap bounding box corners to grid lines, to guides, and to other bounding boxes (only applicable to the selector tool)"), + _rcbsnbb.init (_("_Bounding box corners"), + _("Snap bounding box corners to grid lines, to guides, and to other bounding boxes (Snapping of bounding boxes is only available in the selector tool)"), "inkscape:snap-bbox", _wr); _rcbsnn.init (_("_Nodes"), _("Snap nodes to grid lines, to guides, to paths, and to other nodes"), "inkscape:snap-nodes", _wr); - _rcbsng.init (_("_Guides"), - _("While dragging a guide, snap to object nodes. (In 'Snapping to objects', 'Snap to nodes' must also be enabled)"), - "inkscape:snap-guide", _wr); //Options for snapping to objects - _rcbsnop.init (_("Snap to p_aths"), + _rcbsnop.init (_("Snap to pat_hs"), _("Snap nodes to object paths"), "inkscape:object-paths", _wr); _rcbsnon.init (_("Snap to n_odes"), - _("Snap nodes or guides to object nodes"), - "inkscape:object-nodes", _wr); - _rsu_sno.init (_("Snap _distance"), _("Snap at any dist_ance"), + _("Snap nodes and guides to object nodes"), + "inkscape:object-nodes", _wr); + _rcbsnbbn.init (_("Snap to bounding box co_rners"), + _("Snap bounding box corners to other bounding box corners"), + "inkscape:bbox-nodes", _wr); + _rcbsnbbp.init (_("Snap to bounding box _edges"), + _("Snap bounding box corners and guides to bounding box edges"), + "inkscape:bbox-paths", _wr); + + _rsu_sno.init (_("Snap _distance"), _("Snap at any d_istance"), _("Snapping distance, in screen pixels, for snapping to objects"), _("If set, objects snap to the nearest object, regardless of distance"), "objecttolerance", _wr); //Options for snapping to grids - _rsu_sn.init (_("Snap d_istance"), _("Snap at any distan_ce"), + _rsu_sn.init (_("Snap di_stance"), _("Snap at any dis_tance"), _("Snapping distance, in screen pixels, for snapping to grid"), _("If set, objects snap to the nearest grid line, regardless of distance"), "gridtolerance", _wr); //Options for snapping to guides - _rsu_gusn.init (_("Snap di_stance"), _("Snap at any distanc_e"), + _rsu_gusn.init (_("Snap dist_ance"), _("Snap at any distan_ce"), _("Snapping distance, in screen pixels, for snapping to guides"), _("If set, objects snap to the nearest guide, regardless of distance"), "guidetolerance", _wr); - //Some other options - _rcbic.init (_("_Include the object's rotation center"), - _("Also snap the rotation center of an object when snapping nodes or guides"), - "inkscape:snap-center", _wr); - //Applies to both nodes and guides, but not to bboxes, that's why its located here //Other options to locate here: e.g. visual snapping indicators on/off + std::list slaves; + slaves.push_back(_rcbsnop._button); + slaves.push_back(_rcbsnon._button); + _rcbsnn.setSlaveButton(slaves); + + slaves.clear(); + slaves.push_back(_rcbsnbbp._button); + slaves.push_back(_rcbsnbbn._button); + _rcbsnbb.setSlaveButton(slaves); + Gtk::Label *label_g = manage (new Gtk::Label); label_g->set_markup (_("Snapping of")); Gtk::Label *label_o = manage (new Gtk::Label); @@ -322,31 +333,61 @@ DocumentProperties::build_snap() { label_g, 0, 0, _rcbsnn._button, - //0, 0, //_rcbic._button will be inserted here 0, _rcbsnbb._button, - 0, _rcbsng._button, - 0, 0, + 0, 0, + 0, 0, 0, 0, 0, 0, label_o, 0, 0, _rcbsnop._button, 0, _rcbsnon._button, + 0, _rcbsnbbp._button, + 0, _rcbsnbbn._button, 0, _rsu_sno._vbox, 0, 0, label_gr, 0, 0, _rsu_sn._vbox, 0, 0, label_gu, 0, - 0, _rsu_gusn._vbox, - 0, 0, - 0, 0, - 0, 0, - label_m, 0, - 0, _rcbic._button + 0, _rsu_gusn._vbox }; attach_all(_page_snap.table(), array, G_N_ELEMENTS(array)); } + +void +DocumentProperties::build_snap_dtls() +{ + _page_snap_dtls.show(); + + _rcbsng.init (_("_Snap guides while dragging"), + _("While dragging a guide, snap to object nodes or bounding box corners ('snap to nodes' or 'snap to bounding box corners', both on the previous tab, must be enabled)"), + "inkscape:snap-guide", _wr); + + _rcbic.init (_("_Include the object's rotation center"), + _("Also snap the rotation center of an object when snapping nodes or guides"), + "inkscape:snap-center", _wr); + //Applies to both nodes and guides, but not to bboxes, that's why its located here + + //Other options to locate here: e.g. visual snapping indicators on/off + + Gtk::Label *label_i= manage (new Gtk::Label); + label_i->set_markup (_("Snapping to intersections")); + Gtk::Label *label_m = manage (new Gtk::Label); + label_m->set_markup (_("Miscellaneous")); + + Gtk::Widget *const array[] = + { + label_i, 0, + 0, 0, + 0, 0, + label_m, 0, + 0, _rcbsng._button, + 0, _rcbic._button, + }; + + attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array)); +} /** * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML) @@ -460,6 +501,8 @@ DocumentProperties::update() _rcbic.setActive (nv->snap_manager.getIncludeItemCenter()); _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath()); _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode()); + _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath()); + _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode()); _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 192e2f732..ae8237e3e 100644 --- a/src/ui/dialog/document-properties.h +++ b/src/ui/dialog/document-properties.h @@ -49,6 +49,7 @@ protected: void build_grid(); void build_guides(); void build_snap(); + void build_snap_dtls(); void build_gridspage(); void init(); virtual void on_response (int); @@ -57,7 +58,7 @@ protected: Gtk::Notebook _notebook; NotebookPage _page_page, _page_guides; - NotebookPage _page_snap; + NotebookPage _page_snap, _page_snap_dtls; NotebookPage _page_grids; //--------------------------------------------------------------- @@ -73,7 +74,8 @@ protected: RegisteredUnitMenu _rum_gusn; RegisteredColorPicker _rcp_gui, _rcp_hgui; //--------------------------------------------------------------- - RegisteredCheckButton _rcbsnbb, _rcbsng, _rcbsnn, _rcbic, _rcbsnop, _rcbsnon; + RegisteredCheckButton _rcbsnbb, _rcbsng, _rcbsnn, _rcbic, _rcbsnop; + RegisteredCheckButton _rcbsnon, _rcbsnbbp, _rcbsnbbn; RegisteredUnitMenu _rumso; ToleranceSlider _rsu_sno, _rsu_sn, _rsu_gusn; RegisteredRadioButtonPair _rrb_pix;