~ubuntu-branches/ubuntu/natty/inkscape/natty

« back to all changes in this revision

Viewing changes to src/display/canvas-axonomgrid.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alex Valavanis
  • Date: 2010-09-12 19:44:58 UTC
  • mfrom: (1.1.12 upstream) (45.1.3 maverick)
  • Revision ID: james.westby@ubuntu.com-20100912194458-4sjwmbl7dlsrk5dc
Tags: 0.48.0-1ubuntu1
* Merge with Debian unstable (LP: #628048, LP: #401567, LP: #456248, 
  LP: #463602, LP: #591986)
* debian/control: 
  - Ubuntu maintainers
  - Promote python-lxml, python-numpy, python-uniconvertor to Recommends.
  - Demote pstoedit to Suggests (universe package).
  - Suggests ttf-dejavu instead of ttf-bitstream-vera (LP: #513319)
* debian/rules:
  - Run intltool-update on build (Ubuntu-specific).
  - Add translation domain to .desktop files (Ubuntu-specific).
* debian/dirs:
  - Add usr/share/pixmaps.  Allow inkscape.xpm installation
* drop 50-poppler-API.dpatch (now upstream)
* drop 51-paste-in-unwritable-directory.dpatch (now upstream) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
359
359
    }
360
360
 
361
361
    if ( (value = repr->attribute("snapvisiblegridlinesonly")) ) {
362
 
                g_assert(snapper != NULL);
363
 
                snapper->setSnapVisibleOnly(strcmp(value,"false") != 0 && strcmp(value, "0") != 0);
364
 
        }
 
362
        g_assert(snapper != NULL);
 
363
        snapper->setSnapVisibleOnly(strcmp(value,"false") != 0 && strcmp(value, "0") != 0);
 
364
    }
365
365
 
366
366
    for (GSList *l = canvasitems; l != NULL; l = l->next) {
367
367
        sp_canvas_item_request_update ( SP_CANVAS_ITEM(l->data) );
518
518
{
519
519
    ow = origin * affine;
520
520
    sw = Geom::Point(fabs(affine[0]),fabs(affine[3]));
 
521
    sw *= lengthy;
 
522
 
 
523
    scaled = false;
521
524
 
522
525
    for(int dim = 0; dim < 2; dim++) {
523
526
        gint scaling_factor = empspacing;
525
528
        if (scaling_factor <= 1)
526
529
            scaling_factor = 5;
527
530
 
528
 
        scaled = FALSE;
529
531
        int watchdog = 0;
530
532
        while (  (sw[dim] < 8.0) & (watchdog < 100) ) {
531
 
            scaled = TRUE;
 
533
            scaled = true;
532
534
            sw[dim] *= scaling_factor;
533
535
            // First pass, go up to the major line spacing, then
534
536
            // keep increasing by two.
538
540
 
539
541
    }
540
542
 
541
 
    spacing_ylines = sw[Geom::X] * lengthy  /(tan_angle[X] + tan_angle[Z]);
542
 
    lyw            = sw[Geom::Y] * lengthy;
543
 
    lxw_x          = (lengthy / tan_angle[X]) * sw[Geom::X];
544
 
    lxw_z          = (lengthy / tan_angle[Z]) * sw[Geom::X];
 
543
    spacing_ylines = sw[Geom::X] /(tan_angle[X] + tan_angle[Z]);
 
544
    lyw            = sw[Geom::Y];
 
545
    lxw_x          = sw[Geom::X] / tan_angle[X];
 
546
    lxw_z          = sw[Geom::X] / tan_angle[Z];
545
547
 
546
548
    if (empspacing == 0) {
547
 
        scaled = TRUE;
 
549
        scaled = true;
548
550
    }
549
551
 
550
552
}
671
673
 */
672
674
Geom::Coord CanvasAxonomGridSnapper::getSnapperTolerance() const
673
675
{
674
 
        SPDesktop const *dt = _snapmanager->getDesktop();
675
 
        double const zoom =  dt ? dt->current_zoom() : 1;
676
 
        return _snapmanager->snapprefs.getGridTolerance() / zoom;
 
676
    SPDesktop const *dt = _snapmanager->getDesktop();
 
677
    double const zoom =  dt ? dt->current_zoom() : 1;
 
678
    return _snapmanager->snapprefs.getGridTolerance() / zoom;
677
679
}
678
680
 
679
681
bool CanvasAxonomGridSnapper::getSnapperAlwaysSnap() const
694
696
    double spacing_v;
695
697
 
696
698
    if (getSnapVisibleOnly()) {
697
 
                // Only snapping to visible grid lines
698
 
                spacing_h = grid->spacing_ylines; // this is the spacing of the visible grid lines measured in screen pixels
699
 
                spacing_v = grid->lyw; // vertical
700
 
                // convert screen pixels to px
701
 
                // FIXME: after we switch to snapping dist in screen pixels, this will be unnecessary
702
 
                SPDesktop const *dt = _snapmanager->getDesktop();
703
 
                if (dt) {
704
 
                        spacing_h /= dt->current_zoom();
705
 
                        spacing_v /= dt->current_zoom();
706
 
                }
707
 
        } else {
708
 
                // Snapping to any grid line, whether it's visible or not
709
 
                spacing_h = grid->lengthy  /(grid->tan_angle[X] + grid->tan_angle[Z]);
710
 
                spacing_v = grid->lengthy;
 
699
        // Only snapping to visible grid lines
 
700
        spacing_h = grid->spacing_ylines; // this is the spacing of the visible grid lines measured in screen pixels
 
701
        spacing_v = grid->lyw; // vertical
 
702
        // convert screen pixels to px
 
703
        // FIXME: after we switch to snapping dist in screen pixels, this will be unnecessary
 
704
        SPDesktop const *dt = _snapmanager->getDesktop();
 
705
        if (dt) {
 
706
            spacing_h /= dt->current_zoom();
 
707
            spacing_v /= dt->current_zoom();
 
708
        }
 
709
    } else {
 
710
        // Snapping to any grid line, whether it's visible or not
 
711
        spacing_h = grid->lengthy  /(grid->tan_angle[X] + grid->tan_angle[Z]);
 
712
        spacing_v = grid->lengthy;
711
713
 
712
 
        }
 
714
    }
713
715
 
714
716
    // In an axonometric grid, any point will be surrounded by 6 grid lines:
715
717
    // - 2 vertical grid lines, one left and one right from the point
746
748
    Geom::Point p_x(0, y_proj_along_x_max);
747
749
    Geom::Line line_x(p_x, p_x + vers_x);
748
750
    Geom::Point p_z(0, y_proj_along_z_max);
749
 
        Geom::Line line_z(p_z, p_z + vers_z);
 
751
    Geom::Line line_z(p_z, p_z + vers_z);
750
752
 
751
753
    Geom::OptCrossing inters = Geom::OptCrossing(); // empty by default
752
 
        try
753
 
        {
754
 
                inters = Geom::intersection(line_x, line_z);
755
 
        }
756
 
        catch (Geom::InfiniteSolutions e)
757
 
        {
758
 
                // We're probably dealing with parallel lines; this is useless!
759
 
                return s;
760
 
        }
 
754
    try
 
755
    {
 
756
        inters = Geom::intersection(line_x, line_z);
 
757
    }
 
758
    catch (Geom::InfiniteSolutions e)
 
759
    {
 
760
        // We're probably dealing with parallel lines; this is useless!
 
761
        return s;
 
762
    }
761
763
 
762
764
    // Determine which half of the parallelogram to use
763
765
    bool use_left_half = true;
765
767
 
766
768
    if (inters) {
767
769
        Geom::Point inters_pt = line_x.pointAt((*inters).ta);
768
 
        use_left_half = (p[Geom::X] - grid->origin[Geom::X]) < inters_pt[Geom::X];
 
770
        use_left_half = (p[Geom::X] - grid->origin[Geom::X]) < inters_pt[Geom::X];
769
771
        use_right_half = !use_left_half;
770
772
    }
771
773
 
786
788
    return s;
787
789
}
788
790
 
789
 
void CanvasAxonomGridSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, SnapSourceType const &source, Geom::Point const normal_to_line, Geom::Point const point_on_line) const
 
791
void CanvasAxonomGridSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, SnapSourceType const &source, long source_num, Geom::Point const normal_to_line, Geom::Point const point_on_line) const
790
792
{
791
 
    SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, source, Inkscape::SNAPTARGET_GRID, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line);
 
793
    SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, source, source_num, Inkscape::SNAPTARGET_GRID, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line);
792
794
    sc.grid_lines.push_back(dummy);
793
795
}
794
796
 
795
 
void CanvasAxonomGridSnapper::_addSnappedPoint(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, SnapSourceType const &source) const
 
797
void CanvasAxonomGridSnapper::_addSnappedPoint(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, SnapSourceType const &source, long source_num, bool constrained_snap) const
796
798
{
797
 
        SnappedPoint dummy = SnappedPoint(snapped_point, source, Inkscape::SNAPTARGET_GRID, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), true);
798
 
        sc.points.push_back(dummy);
 
799
    SnappedPoint dummy = SnappedPoint(snapped_point, source, source_num, Inkscape::SNAPTARGET_GRID, snapped_distance, getSnapperTolerance(), getSnapperAlwaysSnap(), constrained_snap, true);
 
800
    sc.points.push_back(dummy);
799
801
}
800
802
 
801
803
bool CanvasAxonomGridSnapper::ThisSnapperMightSnap() const