~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/ui/dialog/transformation.cpp

  • Committer: JazzyNico
  • Date: 2011-08-29 20:25:30 UTC
  • Revision ID: nicoduf@yahoo.fr-20110829202530-6deuoz11q90usldv
Code refactoring and merging with trunk (revision 10599).

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
/* Authors:
5
5
 *   Bryce W. Harrington <bryce@bryceharrington.org>
6
6
 *   buliabyak@gmail.com
 
7
 *   Abhishek Sharma
7
8
 *
8
9
 * Copyright (C) 2004, 2005 Authors
9
10
 * Released under GNU GPL.  Read the file 'COPYING' for more information.
15
16
 
16
17
#include <gtkmm/stock.h>
17
18
#include <gtkmm/dialog.h>
 
19
#include <2geom/transforms.h>
18
20
 
19
21
#include "document.h"
20
22
#include "desktop-handles.h"
21
23
#include "transformation.h"
22
24
#include "align-and-distribute.h"
23
 
#include "libnr/nr-matrix-ops.h"
24
25
#include "inkscape.h"
25
26
#include "selection.h"
26
27
#include "selection-chemistry.h"
27
28
#include "verbs.h"
28
29
#include "preferences.h"
 
30
#include "sp-namedview.h"
29
31
#include "sp-item-transform.h"
30
32
#include "macros.h"
31
33
#include "sp-item.h"
79
81
      _page_rotate            (4, 2),
80
82
      _page_skew              (4, 2),
81
83
      _page_transform         (3, 3),
82
 
      _scalar_move_horizontal (_("_Horizontal"), _("Horizontal displacement (relative) or position (absolute)"), UNIT_TYPE_LINEAR,
 
84
      _scalar_move_horizontal (_("_Horizontal:"), _("Horizontal displacement (relative) or position (absolute)"), UNIT_TYPE_LINEAR,
83
85
                               "", "transform-move-horizontal", &_units_move),
84
 
      _scalar_move_vertical   (_("_Vertical"),  _("Vertical displacement (relative) or position (absolute)"), UNIT_TYPE_LINEAR,
 
86
      _scalar_move_vertical   (_("_Vertical:"),  _("Vertical displacement (relative) or position (absolute)"), UNIT_TYPE_LINEAR,
85
87
                               "", "transform-move-vertical", &_units_move),
86
 
      _scalar_scale_horizontal(_("_Width"), _("Horizontal size (absolute or percentage of current)"), UNIT_TYPE_DIMENSIONLESS,
 
88
      _scalar_scale_horizontal(_("_Width:"), _("Horizontal size (absolute or percentage of current)"), UNIT_TYPE_DIMENSIONLESS,
87
89
                               "", "transform-scale-horizontal", &_units_scale),
88
 
      _scalar_scale_vertical  (_("_Height"),  _("Vertical size (absolute or percentage of current)"), UNIT_TYPE_DIMENSIONLESS,
 
90
      _scalar_scale_vertical  (_("_Height:"),  _("Vertical size (absolute or percentage of current)"), UNIT_TYPE_DIMENSIONLESS,
89
91
                               "", "transform-scale-vertical", &_units_scale),
90
 
      _scalar_rotate          (_("A_ngle"), _("Rotation angle (positive = counterclockwise)"), UNIT_TYPE_RADIAL,
 
92
      _scalar_rotate          (_("A_ngle:"), _("Rotation angle (positive = counterclockwise)"), UNIT_TYPE_RADIAL,
91
93
                               "", "transform-rotate", &_units_rotate),
92
 
      _scalar_skew_horizontal (_("_Horizontal"), _("Horizontal skew angle (positive = counterclockwise), or absolute displacement, or percentage displacement"), UNIT_TYPE_LINEAR,
 
94
      _scalar_skew_horizontal (_("_Horizontal:"), _("Horizontal skew angle (positive = counterclockwise), or absolute displacement, or percentage displacement"), UNIT_TYPE_LINEAR,
93
95
                               "", "transform-skew-horizontal", &_units_skew),
94
 
      _scalar_skew_vertical   (_("_Vertical"),  _("Vertical skew angle (positive = counterclockwise), or absolute displacement, or percentage displacement"),  UNIT_TYPE_LINEAR,
 
96
      _scalar_skew_vertical   (_("_Vertical:"),  _("Vertical skew angle (positive = counterclockwise), or absolute displacement, or percentage displacement"),  UNIT_TYPE_LINEAR,
95
97
                               "", "transform-skew-vertical", &_units_skew),
96
98
 
97
 
      _scalar_transform_a     ("_A", _("Transformation matrix element A")),
98
 
      _scalar_transform_b     ("_B", _("Transformation matrix element B")),
99
 
      _scalar_transform_c     ("_C", _("Transformation matrix element C")),
100
 
      _scalar_transform_d     ("_D", _("Transformation matrix element D")),
101
 
      _scalar_transform_e     ("_E", _("Transformation matrix element E")),
102
 
      _scalar_transform_f     ("_F", _("Transformation matrix element F")),
 
99
      _scalar_transform_a     ("_A:", _("Transformation matrix element A")),
 
100
      _scalar_transform_b     ("_B:", _("Transformation matrix element B")),
 
101
      _scalar_transform_c     ("_C:", _("Transformation matrix element C")),
 
102
      _scalar_transform_d     ("_D:", _("Transformation matrix element D")),
 
103
      _scalar_transform_e     ("_E:", _("Transformation matrix element E")),
 
104
      _scalar_transform_f     ("_F:", _("Transformation matrix element F")),
103
105
 
104
106
      _check_move_relative    (_("Rela_tive move"), _("Add the specified relative displacement to the current position; otherwise, edit the current absolute position directly")),
105
 
      _check_scale_proportional (_("Scale proportionally"), _("Preserve the width/height ratio of the scaled objects")),
 
107
      _check_scale_proportional (_("_Scale proportionally"), _("Preserve the width/height ratio of the scaled objects")),
106
108
      _check_apply_separately    (_("Apply to each _object separately"), _("Apply the scale/rotate/skew to each selected object separately; otherwise, transform the selection as a whole")),
107
109
      _check_replace_matrix    (_("Edit c_urrent matrix"), _("Edit the current transform= matrix; otherwise, post-multiply transform= by this matrix"))
108
110
 
198
200
Transformation::layoutPageMove()
199
201
{
200
202
    _units_move.setUnitType(UNIT_TYPE_LINEAR);
 
203
    
 
204
    // Setting default unit to document unit
 
205
    SPDesktop *dt = getDesktop();
 
206
    SPNamedView *nv = sp_desktop_namedview(dt);
 
207
    if (nv->doc_units) {
 
208
        _units_move.setUnit(nv->doc_units->abbr);
 
209
    }
 
210
    
201
211
    _scalar_move_horizontal.initScalar(-1e6, 1e6);
202
212
    _scalar_move_horizontal.setDigits(3);
203
213
    _scalar_move_horizontal.setIncrements(0.1, 1.0);
457
467
{
458
468
    if (selection && !selection->isEmpty()) {
459
469
        if (!_check_move_relative.get_active()) {
460
 
            Geom::OptRect bbox = selection->bounds();
 
470
            Geom::OptRect bbox = selection->visualBounds();
461
471
            if (bbox) {
462
472
                double x = bbox->min()[Geom::X];
463
473
                double y = bbox->min()[Geom::Y];
464
474
 
465
 
                _scalar_move_horizontal.setValue(x, "px");
466
 
                _scalar_move_vertical.setValue(y, "px");
 
475
                double conversion = _units_move.getConversion("px");
 
476
                _scalar_move_horizontal.setValue(x / conversion);
 
477
                _scalar_move_vertical.setValue(y / conversion);
467
478
            }
468
479
        } else {
469
480
            // do nothing, so you can apply the same relative move to many objects in turn
478
489
Transformation::updatePageScale(Inkscape::Selection *selection)
479
490
{
480
491
    if (selection && !selection->isEmpty()) {
481
 
        Geom::OptRect bbox = selection->bounds();
 
492
        Geom::OptRect bbox = selection->visualBounds();
482
493
        if (bbox) {
483
494
            double w = bbox->dimensions()[Geom::X];
484
495
            double h = bbox->dimensions()[Geom::Y];
508
519
Transformation::updatePageSkew(Inkscape::Selection *selection)
509
520
{
510
521
    if (selection && !selection->isEmpty()) {
511
 
        Geom::OptRect bbox = selection->bounds();
 
522
        Geom::OptRect bbox = selection->visualBounds();
512
523
        if (bbox) {
513
524
            double w = bbox->dimensions()[Geom::X];
514
525
            double h = bbox->dimensions()[Geom::Y];
528
539
{
529
540
    if (selection && !selection->isEmpty()) {
530
541
        if (_check_replace_matrix.get_active()) {
531
 
            Geom::Matrix current (SP_ITEM(selection->itemList()->data)->transform); // take from the first item in selection
 
542
            Geom::Affine current (SP_ITEM(selection->itemList()->data)->transform); // take from the first item in selection
532
543
 
533
 
            Geom::Matrix new_displayed = current;
 
544
            Geom::Affine new_displayed = current;
534
545
 
535
546
            _scalar_transform_a.setValue(new_displayed[0]);
536
547
            _scalar_transform_b.setValue(new_displayed[1]);
605
616
        if (_check_move_relative.get_active()) {
606
617
            sp_selection_move_relative(selection, x, y);
607
618
        } else {
608
 
            Geom::OptRect bbox = selection->bounds();
 
619
            Geom::OptRect bbox = selection->visualBounds();
609
620
            if (bbox) {
610
621
                sp_selection_move_relative(selection,
611
622
                                           x - bbox->min()[Geom::X], y - bbox->min()[Geom::Y]);
626
637
                     it != selected.end();
627
638
                     ++it)
628
639
                {
629
 
                    Geom::OptRect bbox = sp_item_bbox_desktop(*it);
 
640
                    Geom::OptRect bbox = (*it)->desktopVisualBounds();
630
641
                    if (bbox) {
631
642
                        sorted.push_back(BBoxSort(*it, *bbox, Geom::X, x > 0? 1. : 0., x > 0? 0. : 1.));
632
643
                    }
650
661
                     it != selected.end();
651
662
                     ++it)
652
663
                {
653
 
                    Geom::OptRect bbox = sp_item_bbox_desktop(*it);
 
664
                    Geom::OptRect bbox = (*it)->desktopVisualBounds();
654
665
                    if (bbox) {
655
666
                        sorted.push_back(BBoxSort(*it, *bbox, Geom::Y, y > 0? 1. : 0., y > 0? 0. : 1.));
656
667
                    }
669
680
                }
670
681
            }
671
682
        } else {
672
 
            Geom::OptRect bbox = selection->bounds();
 
683
            Geom::OptRect bbox = selection->visualBounds();
673
684
            if (bbox) {
674
685
                sp_selection_move_relative(selection,
675
686
                                           x - bbox->min()[Geom::X], y - bbox->min()[Geom::Y]);
677
688
        }
678
689
    }
679
690
 
680
 
    sp_document_done ( sp_desktop_document (selection->desktop()) , SP_VERB_DIALOG_TRANSFORM,
681
 
                       _("Move"));
 
691
    DocumentUndo::done( sp_desktop_document(selection->desktop()) , SP_VERB_DIALOG_TRANSFORM,
 
692
                        _("Move"));
682
693
}
683
694
 
684
695
void
694
705
            Geom::Scale scale (0,0);
695
706
            // the values are increments!
696
707
            if (_units_scale.isAbsolute()) {
697
 
                Geom::OptRect bbox(sp_item_bbox_desktop(item));
 
708
                Geom::OptRect bbox = item->desktopVisualBounds();
698
709
                if (bbox) {
699
710
                    double new_width = scaleX;
700
711
                    if (fabs(new_width) < 1e-6) new_width = 1e-6; // not 0, as this would result in a nasty no-bbox object
712
723
            sp_item_scale_rel (item, scale);
713
724
        }
714
725
    } else {
715
 
        Geom::OptRect bbox(selection->bounds());
 
726
        Geom::OptRect bbox = selection->visualBounds();
716
727
        if (bbox) {
717
728
            Geom::Point center(bbox->midpoint()); // use rotation center?
718
729
            Geom::Scale scale (0,0);
734
745
        }
735
746
    }
736
747
 
737
 
    sp_document_done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
738
 
                     _("Scale"));
 
748
    DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
 
749
                       _("Scale"));
739
750
}
740
751
 
741
752
void
756
767
        }
757
768
    }
758
769
 
759
 
    sp_document_done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
760
 
                     _("Rotate"));
 
770
    DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
 
771
                       _("Rotate"));
761
772
}
762
773
 
763
774
void
781
792
            } else { // absolute displacement
782
793
                double skewX = _scalar_skew_horizontal.getValue("px");
783
794
                double skewY = _scalar_skew_vertical.getValue("px");
784
 
                Geom::OptRect bbox(sp_item_bbox_desktop(item));
 
795
                Geom::OptRect bbox = item->desktopVisualBounds();
785
796
                if (bbox) {
786
797
                    double width = bbox->dimensions()[Geom::X];
787
798
                    double height = bbox->dimensions()[Geom::Y];
790
801
            }
791
802
        }
792
803
    } else { // transform whole selection
793
 
        Geom::OptRect bbox = selection->bounds();
 
804
        Geom::OptRect bbox = selection->visualBounds();
794
805
        boost::optional<Geom::Point> center = selection->center();
795
806
 
796
807
        if ( bbox && center ) {
815
826
        }
816
827
    }
817
828
 
818
 
    sp_document_done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
819
 
                     _("Skew"));
 
829
    DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
 
830
                       _("Skew"));
820
831
}
821
832
 
822
833
 
830
841
    double e = _scalar_transform_e.getValue();
831
842
    double f = _scalar_transform_f.getValue();
832
843
 
833
 
    Geom::Matrix displayed(a, b, c, d, e, f);
 
844
    Geom::Affine displayed(a, b, c, d, e, f);
834
845
 
835
846
    if (_check_replace_matrix.get_active()) {
836
847
        for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
837
848
            SPItem *item = SP_ITEM(l->data);
838
 
            sp_item_set_item_transform(item, displayed);
 
849
            item->set_item_transform(displayed);
839
850
            SP_OBJECT(item)->updateRepr();
840
851
        }
841
852
    } else {
842
853
        sp_selection_apply_affine(selection, displayed); // post-multiply each object's transform
843
854
    }
844
855
 
845
 
    sp_document_done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
846
 
                     _("Edit transformation matrix"));
 
856
    DocumentUndo::done(sp_desktop_document(selection->desktop()), SP_VERB_DIALOG_TRANSFORM,
 
857
                       _("Edit transformation matrix"));
847
858
}
848
859
 
849
860
 
871
882
    double x = _scalar_move_horizontal.getValue("px");
872
883
    double y = _scalar_move_vertical.getValue("px");
873
884
 
 
885
    double conversion = _units_move.getConversion("px");
 
886
 
874
887
    //g_message("onMoveRelativeToggled: %f, %f px\n", x, y);
875
888
 
876
 
    Geom::OptRect bbox = selection->bounds();
 
889
    Geom::OptRect bbox = selection->visualBounds();
877
890
 
878
891
    if (bbox) {
879
892
        if (_check_move_relative.get_active()) {
880
893
            // From absolute to relative
881
 
            _scalar_move_horizontal.setValue(x - bbox->min()[Geom::X], "px");
882
 
            _scalar_move_vertical.setValue(  y - bbox->min()[Geom::Y], "px");
 
894
            _scalar_move_horizontal.setValue((x - bbox->min()[Geom::X]) / conversion);
 
895
            _scalar_move_vertical.setValue((  y - bbox->min()[Geom::Y]) / conversion);
883
896
        } else {
884
897
            // From relative to absolute
885
 
            _scalar_move_horizontal.setValue(bbox->min()[Geom::X] + x, "px");
886
 
            _scalar_move_vertical.setValue(  bbox->min()[Geom::Y] + y, "px");
 
898
            _scalar_move_horizontal.setValue((bbox->min()[Geom::X] + x) / conversion);
 
899
            _scalar_move_vertical.setValue((  bbox->min()[Geom::Y] + y) / conversion);
887
900
        }
888
901
    }
889
902
 
976
989
    double e = _scalar_transform_e.getValue();
977
990
    double f = _scalar_transform_f.getValue();
978
991
 
979
 
    Geom::Matrix displayed (a, b, c, d, e, f);
980
 
    Geom::Matrix current = SP_ITEM(selection->itemList()->data)->transform; // take from the first item in selection
 
992
    Geom::Affine displayed (a, b, c, d, e, f);
 
993
    Geom::Affine current = SP_ITEM(selection->itemList()->data)->transform; // take from the first item in selection
981
994
 
982
 
    Geom::Matrix new_displayed;
 
995
    Geom::Affine new_displayed;
983
996
    if (_check_replace_matrix.get_active()) {
984
997
        new_displayed = current;
985
998
    } else {
1013
1026
            _scalar_move_horizontal.setValue(0);
1014
1027
            _scalar_move_vertical.setValue(0);
1015
1028
        } else {
1016
 
            Geom::OptRect bbox = selection->bounds();
 
1029
            Geom::OptRect bbox = selection->visualBounds();
1017
1030
            if (bbox) {
1018
1031
                _scalar_move_horizontal.setValue(bbox->min()[Geom::X], "px");
1019
1032
                _scalar_move_vertical.setValue(bbox->min()[Geom::Y], "px");
1068
1081
  fill-column:99
1069
1082
  End:
1070
1083
*/
1071
 
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
 
1084
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :