Code

Snap to page border
authordvlierop2 <dvlierop2@users.sourceforge.net>
Wed, 12 Mar 2008 00:08:38 +0000 (00:08 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Wed, 12 Mar 2008 00:08:38 +0000 (00:08 +0000)
src/attributes-test.h
src/attributes.cpp
src/attributes.h
src/object-snapper.cpp
src/object-snapper.h
src/sp-namedview.cpp
src/ui/dialog/document-properties.cpp
src/ui/dialog/document-properties.h

index cdc82a475aa98ec4f1aca5274556b75e8f144d3e..b5c05e988fb4483235b6c8e8b2ac3edaa53ed9e4 100644 (file)
@@ -345,6 +345,7 @@ struct {char const *attr; bool supported;} const all_attrs[] = {
     {"inkscape:object-nodes", true},
     {"inkscape:bbox-paths", true},
     {"inkscape:bbox-nodes", true},
+    {"inkscape:snap-page", true},
     {"inkscape:snap-global", true},
     {"inkscape:snap-bbox", true},
     {"inkscape:snap-nodes", true},
index 66a7b66c895f1f6ea2944257b0b0be787ad36a6a..a8ecb872bfe977901a54fc560671978c917968f2 100644 (file)
@@ -96,6 +96,7 @@ static SPStyleProp const props[] = {
     {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_SNAP_PAGE, "inkscape:snap-page"},
     {SP_ATTR_INKSCAPE_CURRENT_LAYER, "inkscape:current-layer"},
     {SP_ATTR_INKSCAPE_DOCUMENT_UNITS, "inkscape:document-units"},
     {SP_ATTR_INKSCAPE_CONNECTOR_SPACING, "inkscape:connector-spacing"},
index b59c17ec8c7759808a9f952aa6403e6c2433dd6c..8591258fe92ffdc7fa43ac253ab1a19849924f12 100644 (file)
@@ -96,6 +96,7 @@ enum SPAttributeEnum {
     SP_ATTR_INKSCAPE_OBJECT_NODES,
     SP_ATTR_INKSCAPE_BBOX_PATHS,
     SP_ATTR_INKSCAPE_BBOX_NODES,
+    SP_ATTR_INKSCAPE_SNAP_PAGE,
     SP_ATTR_INKSCAPE_CURRENT_LAYER,
     SP_ATTR_INKSCAPE_DOCUMENT_UNITS,
     SP_ATTR_INKSCAPE_CONNECTOR_SPACING,
index 6c94679ecb0b33245273194c100f59e765cb1c12..934925ad04eb268c8fe0d58d993e4cb0b3a19775 100644 (file)
@@ -34,7 +34,7 @@
 Inkscape::ObjectSnapper::ObjectSnapper(SPNamedView const *nv, NR::Coord const d)
     : Snapper(nv, d), _snap_to_itemnode(true), _snap_to_itempath(true),
     _snap_to_bboxnode(true), _snap_to_bboxpath(true), _strict_snapping(true),
-    _include_item_center(false)
+    _snap_to_page_border(false), _include_item_center(false)
 {
     _candidates = new std::vector<SPItem*>;
     _points_to_snap_to = new std::vector<NR::Point>;
@@ -251,7 +251,8 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuideToNodes(SnappedConstraints &s
 
 void Inkscape::ObjectSnapper::_collectPaths(Inkscape::Snapper::PointType const &t,
                                          bool const &first_point,
-                                         SPPath const *selected_path) const
+                                         SPPath const *selected_path,
+                                         NArtBpath *border_bpath) const
 {
     // Now, let's first collect all paths to snap to. If we have a whole bunch of points to snap,
     // e.g. when translating an item using the selector tool, then we will only do this for the
@@ -269,6 +270,11 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::Snapper::PointType const &
             bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;
         }
         
+        // Consider the page border for snapping
+        if (border_bpath != NULL) { 
+            _bpaths_to_snap_to->push_back(border_bpath);    
+        }
+        
         /* While editing a path in the node tool, findCandidates must ignore that path because 
          * of the node snapping requirements (i.e. only unselected nodes must be snapable).
          * This path must not be ignored however when snapping to the paths, so we add it here
@@ -350,9 +356,10 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc,
                                      NR::Point const &p,
                                      bool const &first_point,
                                      std::vector<NR::Point> *unselected_nodes,
-                                     SPPath const *selected_path) const
+                                     SPPath const *selected_path,
+                                     NArtBpath *border_bpath) const
 {
-    _collectPaths(t, first_point, selected_path);
+    _collectPaths(t, first_point, selected_path, border_bpath);
     
     // Now we can finally do the real snapping, using the paths collected above
     SnappedPoint s;
@@ -417,7 +424,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc,
                     (*k)->PointAt(o->piece, 0, start_point);
                     (*k)->PointAt(o->piece, 1, end_point);
                     start_point = desktop->doc2dt(start_point);
-                    end_point = desktop->doc2dt(end_point);                        
+                    end_point = desktop->doc2dt(end_point);        
                 }
                 
                 if (o && o->t >= 0 && o->t <= 1) {    
@@ -478,7 +485,11 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc,
                                      bool const &first_point,
                                      ConstraintLine const &c) const
 {
-    _collectPaths(t, first_point);
+    
+    // Consider the page's border for snapping to
+    NArtBpath *border_bpath = _snap_to_page_border ? _getBorderBPath() : NULL;
+    
+    _collectPaths(t, first_point, NULL, border_bpath);
     
     // Now we can finally do the real snapping, using the paths collected above
     
@@ -506,7 +517,7 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc,
     Geom::Path cl;
     cl.start(p_min_on_cl.to_2geom());
     cl.appendNew<Geom::LineSegment>(p_max_on_cl.to_2geom());
-        
+    
     for (std::vector<NArtBpath*>::const_iterator k = _bpaths_to_snap_to->begin(); k != _bpaths_to_snap_to->end(); k++) {
         if (*k) {                        
             // convert a Path object (see src/livarot/Path.h) to a 2geom's path object (see 2geom/path.h)
@@ -554,7 +565,10 @@ void Inkscape::ObjectSnapper::_doFreeSnap(SnappedConstraints &sc,
         _snapNodes(sc, t, p, first_point, unselected_nodes);
     }
     
-    if (_snap_to_itempath || _snap_to_bboxpath) {
+    // Consider the page's border for snapping to
+    NArtBpath *border_bpath = _snap_to_page_border ? _getBorderBPath() : NULL;   
+    
+    if (_snap_to_itempath || _snap_to_bboxpath || _snap_to_page_border) {
         unsigned n = (unselected_nodes == NULL) ? 0 : unselected_nodes->size();
         if (n > 0) {
             /* While editing a path in the node tool, findCandidates must ignore that path because 
@@ -564,15 +578,14 @@ void Inkscape::ObjectSnapper::_doFreeSnap(SnappedConstraints &sc,
              */
             g_assert(it.size() == 1);
             g_assert(SP_IS_PATH(*it.begin()));
-            _snapPaths(sc, t, p, first_point, unselected_nodes, SP_PATH(*it.begin()));    
+            _snapPaths(sc, t, p, first_point, unselected_nodes, SP_PATH(*it.begin()), border_bpath);
+                
         } else {
-            _snapPaths(sc, t, p, first_point, NULL, NULL);   
+            _snapPaths(sc, t, p, first_point, NULL, NULL, border_bpath);   
         }        
     }
 }
 
-
-
 void Inkscape::ObjectSnapper::_doConstrainedSnap( SnappedConstraints &sc,
                                                   Inkscape::Snapper::PointType const &t,
                                                   NR::Point const &p,
@@ -599,7 +612,7 @@ void Inkscape::ObjectSnapper::_doConstrainedSnap( SnappedConstraints &sc,
     // to objects we will only consider the object's paths. Beside, the nodes will be at these paths,
     // so we will more or less snap to them anyhow.   
 
-    if (_snap_to_itempath || _snap_to_bboxpath) {
+    if (_snap_to_itempath || _snap_to_bboxpath || _snap_to_page_border) {
         _snapPathsConstrained(sc, t, p, first_point, c);
     }
 }
@@ -650,7 +663,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;
+    bool snap_to_something = _snap_to_itempath || _snap_to_itemnode || _snap_to_bboxpath || _snap_to_bboxnode || _snap_to_page_border;
     return (_snap_enabled && _snap_from != 0 && snap_to_something);
 }
 
@@ -673,6 +686,17 @@ void Inkscape::ObjectSnapper::_clear_paths() const
     _paths_to_snap_to->clear();
 }
 
+NArtBpath* Inkscape::ObjectSnapper::_getBorderBPath() const
+{
+    NArtBpath *border_bpath = NULL;
+    NR::Rect const border_rect = NR::Rect(NR::Point(0,0), NR::Point(sp_document_width(_named_view->document),sp_document_height(_named_view->document)));
+    SPCurve const *border_curve = sp_curve_new_from_rect(border_rect);
+    if (border_curve) {
+        border_bpath = SP_CURVE_BPATH(border_curve); 
+    }
+        
+    return border_bpath;
+}
 /*
   Local Variables:
   mode:c++
index ef43af0e97790442e482d7a2481a614246b59b97..32dd0fb3bb5b0bde43870fc55db4cdcec47eb0e5 100644 (file)
@@ -71,6 +71,14 @@ public:
     return _snap_to_bboxpath;
   }
   
+  void setSnapToPageBorder(bool s) {
+    _snap_to_page_border = s;
+  }
+
+  bool getSnapToPageBorder() const {
+    return _snap_to_page_border;
+  }
+    
   void setIncludeItemCenter(bool s) {
     _include_item_center = s;
   }
@@ -137,7 +145,8 @@ private:
                       NR::Point const &p,
                       bool const &first_point,
                       std::vector<NR::Point> *unselected_nodes,
-                      SPPath const *selected_path) const;
+                      SPPath const *selected_path,
+                      NArtBpath *border_bpath) const;
                       
   void _snapPathsConstrained(SnappedConstraints &sc,
                  Inkscape::Snapper::PointType const &t,
@@ -148,13 +157,16 @@ private:
   
   void _collectPaths(Inkscape::Snapper::PointType const &t, 
                   bool const &first_point,
-                  SPPath const *selected_path = NULL) const;
+                  SPPath const *selected_path = NULL,
+                  NArtBpath *border_bpath = NULL) const;
   void _clear_paths() const;
+  NArtBpath* _getBorderBPath() const;
   
   bool _snap_to_itemnode;
   bool _snap_to_itempath;
   bool _snap_to_bboxnode;
   bool _snap_to_bboxpath;
+  bool _snap_to_page_border;
   
   //If enabled, then bbox corners will only snap to bboxes, 
   //and nodes will only snap to nodes and paths. We will not
index 268150a16002816c7f8d95657251cf44c3d49659..ec0552653b76c3106575eb7eb431d6800a9a6680 100644 (file)
@@ -256,6 +256,7 @@ static void sp_namedview_build(SPObject *object, SPDocument *document, Inkscape:
     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:snap-page");
     sp_object_read_attr(object, "inkscape:current-layer");
     sp_object_read_attr(object, "inkscape:connector-spacing");
 
@@ -495,6 +496,10 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va
             nv->snap_manager.object.setSnapToBBoxNode(value ? sp_str_to_bool(value) : FALSE);
             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
             break;
+    case SP_ATTR_INKSCAPE_SNAP_PAGE:
+            nv->snap_manager.object.setSnapToPageBorder(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);
index ac4fb9285c987fc3768dca4d6420a036a9b5d7a7..acf76f034bb288005fddf96d5c8708502d53c937 100644 (file)
@@ -8,9 +8,10 @@
  *   Lauris Kaplinski <lauris@kaplinski.com>
  *   Jon Phillips <jon@rejon.org>
  *   Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
+ *   Diederik van Lierop <mail@diedenrezi.nl>
  *
  * Copyright (C) 2006-2008 Johan Engelen  <johan@shouraizou.nl>
- * Copyright (C) 2000 - 2005 Authors
+ * Copyright (C) 2000 - 2008 Authors
  *
  * Released under GNU GPL.  Read the file 'COPYING' for more information
  */
@@ -109,6 +110,7 @@ DocumentProperties::DocumentProperties()
       _rcbsnon(_("Snap to n_odes"), _("Snap nodes and guides to object nodes"), "inkscape:object-nodes", _wr),
       _rcbsnbbp(_("Snap to bounding bo_x edges"), _("Snap bounding box corners and guides to bounding box edges"), "inkscape:bbox-paths", _wr),
       _rcbsnbbn(_("Snap to bounding box co_rners"), _("Snap bounding box corners to other bounding box corners"), "inkscape:bbox-nodes", _wr),
+      _rcbsnpb(_("Snap to page border"), _("Snap bounding box corners and nodes to the page border"), "inkscape:snap-page", _wr),
     //---------------------------------------------------------------
        //Applies to both nodes and guides, but not to bboxes, that's why its located here
       _rcbic( _("Rotation _center"), _("Consider the rotation center of an object when snapping"), "inkscape:snap-center", _wr),
@@ -332,6 +334,7 @@ DocumentProperties::build_snap()
         0,                  &_rcbsnon,
         0,                  &_rcbsnbbp,
         0,                  &_rcbsnbbn,
+        0,                  &_rcbsnpb,
         0,                  _rsu_sno._vbox,
         0,                  0,
         label_gr,           0,
@@ -494,6 +497,7 @@ DocumentProperties::update()
     _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
     _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
     _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
+    _rcbsnpb.setActive(nv->snap_manager.object.getSnapToPageBorder());
     _rsu_sno.setValue (nv->objecttolerance);
 
     _rsu_sn.setValue (nv->gridtolerance);
index d2509d8a46d3193b1cb3ebeb1fb37fee6d9ceda0..6d6b77e5d40c9836fd1a20c941c053336dc0dd0f 100644 (file)
@@ -75,7 +75,7 @@ protected:
     RegisteredColorPicker _rcp_gui, _rcp_hgui;
     //---------------------------------------------------------------
     RegisteredCheckButton _rcbsg, _rcbsnbb, _rcbsnn, _rcbsnop;
-    RegisteredCheckButton _rcbsnon, _rcbsnbbp, _rcbsnbbn;
+    RegisteredCheckButton _rcbsnon, _rcbsnbbp, _rcbsnbbn, _rcbsnpb;
     ToleranceSlider       _rsu_sno, _rsu_sn, _rsu_gusn;
     //---------------------------------------------------------------
     RegisteredCheckButton _rcbic;