~danieljabailey/inkscape/arc_node_editor

« back to all changes in this revision

Viewing changes to src/selection-chemistry.cpp

  • Committer: Jabiertxof
  • Date: 2015-05-09 17:31:55 UTC
  • Revision ID: jtx@jtx.marker.es-20150509173155-br934thscki7ur1u
Fix Doxyfile

Show diffs side-by-side

added added

removed removed

Lines of Context:
284
284
 
285
285
    std::vector<SPItem*> const selList = selection->itemList();
286
286
 
287
 
    for( std::vector<SPItem*>::const_reverse_iterator i = selList.rbegin(); i != selList.rend(); ++i ) {
 
287
    for( std::vector<SPItem*>::const_reverse_iterator i = selList.rbegin(); i != selList.rend(); i++ ) {
288
288
        SPItem *item = *i;
289
289
        if( item &&
290
290
            !dt->isLayer(item) &&
330
330
    sort(sorted_items.begin(),sorted_items.end(),sp_object_compare_position_bool);
331
331
 
332
332
    // Copy item reprs:
333
 
    for (std::vector<SPItem*>::const_iterator i = sorted_items.begin(); i != sorted_items.end(); ++i) {
 
333
    for (std::vector<SPItem*>::const_iterator i = sorted_items.begin(); i != sorted_items.end(); i++) {
334
334
        SPItem *item = *i;
335
335
        if (item) {
336
336
            sp_selection_copy_one(item->getRepr(), item->i2doc_affine(), clip, xml_doc);
351
351
 
352
352
    std::vector<Inkscape::XML::Node*> copied;
353
353
    // add objects to document
354
 
    for (std::vector<Inkscape::XML::Node*>::const_iterator l = clip.begin(); l != clip.end(); ++l) {
 
354
    for (std::vector<Inkscape::XML::Node*>::const_iterator l = clip.begin(); l != clip.end(); l++) {
355
355
        Inkscape::XML::Node *repr = *l;
356
356
        Inkscape::XML::Node *copy = repr->duplicate(xml_doc);
357
357
 
378
378
 
379
379
static void sp_selection_delete_impl(std::vector<SPItem*> const &items, bool propagate = true, bool propagate_descendants = true)
380
380
{
381
 
    for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); ++i) {
 
381
    for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++) {
382
382
        sp_object_ref(*i, NULL);
383
383
    }
384
 
    for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); ++i) {
 
384
    for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++) {
385
385
        SPItem *item = *i;
386
386
        item->deleteObject(propagate, propagate_descendants);
387
387
        sp_object_unref(item, NULL);
475
475
    bool relink_clones = prefs->getBool("/options/relinkclonesonduplicate/value");
476
476
    const bool fork_livepatheffects = prefs->getBool("/options/forklpeonduplicate/value", true);
477
477
 
478
 
    for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();++i){
 
478
    for(std::vector<Inkscape::XML::Node*>::const_reverse_iterator i=reprs.rbegin();i!=reprs.rend();i++){
479
479
        Inkscape::XML::Node *old_repr = *i;
480
480
        Inkscape::XML::Node *parent = old_repr->parent();
481
481
        Inkscape::XML::Node *copy = old_repr->duplicate(xml_doc);
483
483
        if(! duplicateLayer)
484
484
            parent->appendChild(copy);
485
485
        else
486
 
            parent->addChild(copy, old_repr);
 
486
                parent->addChild(copy, old_repr);
487
487
 
488
488
        if (relink_clones) {
489
489
            SPObject *old_obj = doc->getObjectByRepr(old_repr);
547
547
    if(!duplicateLayer)
548
548
        selection->setReprList(newsel);
549
549
    else{
550
 
        SPObject* new_layer = doc->getObjectByRepr(newsel[0]);
 
550
        SPObject* new_layer = doc->getObjectByRepr(newsel[0]);
551
551
        gchar* name = g_strdup_printf(_("%s copy"), new_layer->label());
552
552
        desktop->layer_manager->renameLayer( new_layer, name, TRUE );
553
553
        g_free(name);
638
638
 
639
639
        std::vector<SPItem*> all_items = sp_item_group_item_list(dynamic_cast<SPGroup *>(dt->currentLayer()));
640
640
 
641
 
        for (std::vector<SPItem*>::const_reverse_iterator i=all_items.rbegin();i!=all_items.rend();++i) {
 
641
        for (std::vector<SPItem*>::const_reverse_iterator i=all_items.rbegin();i!=all_items.rend();i++) {
642
642
            SPItem *item = *i;
643
643
 
644
644
            if (item && (!onlysensitive || !item->isLocked())) {
655
655
            break;
656
656
        }
657
657
        case PREFS_SELECTION_LAYER_RECURSIVE: {
658
 
            std::vector<SPItem*> x;
 
658
                std::vector<SPItem*> x;
659
659
            items = get_all_items(x, dt->currentLayer(), dt, onlyvisible, onlysensitive, FALSE, exclude);
660
660
            break;
661
661
        }
698
698
    gint topmost = p.back()->position();
699
699
    Inkscape::XML::Node *topmost_parent = p.back()->parent();
700
700
 
701
 
    for(std::vector<Inkscape::XML::Node*>::const_iterator i = p.begin(); i != p.end(); ++i){
 
701
    for(std::vector<Inkscape::XML::Node*>::const_iterator i = p.begin(); i != p.end(); i++){
702
702
        Inkscape::XML::Node *current = *i;
703
703
 
704
704
        if (current->parent() == topmost_parent) {
791
791
        return -1;
792
792
    }
793
793
}
794
 
 
795
 
void sp_selection_ungroup_pop_selection(Inkscape::Selection *selection, SPDesktop *desktop)
796
 
{
797
 
    if (selection->isEmpty()) {
798
 
        selection_display_message(desktop, Inkscape::WARNING_MESSAGE, _("<b>No objects selected</b> to pop out of group."));
799
 
        return;
800
 
    }
801
 
    std::vector<SPItem*>  selection_list = selection->itemList();
802
 
 
803
 
    std::vector<SPItem*>::const_iterator item = selection_list.begin(); // leaving this because it will be useful for
804
 
                                                                        // future implementation of complex pop ungrouping
805
 
    SPItem *obj = *item;
806
 
    SPItem *parent_group = static_cast<SPItem*>(obj->parent);
807
 
    if (!SP_IS_GROUP(parent_group) || SP_IS_LAYER(parent_group)) {
808
 
        desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Selection <b>not in a group</b>."));
809
 
        return;
810
 
    }
811
 
    if (parent_group->firstChild()->getNext() == NULL) {
812
 
        std::vector<SPItem*> children;
813
 
        sp_item_group_ungroup(static_cast<SPGroup*>(parent_group), children, false);
814
 
    }
815
 
    else {
816
 
        sp_selection_to_next_layer(desktop, 1); // suppress done
817
 
    }
818
 
 
819
 
    parent_group->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
820
 
    
821
 
    DocumentUndo::done(selection->layers()->getDocument(), SP_VERB_SELECTION_UNGROUP_POP_SELECTION,
822
 
                       _("Pop selection from group"));
823
 
    
824
 
}
825
 
 
826
794
 
827
795
void sp_selection_ungroup(Inkscape::Selection *selection, SPDesktop *desktop)
828
796
{
834
802
    std::vector<SPItem*> old_select = selection->itemList();
835
803
    std::vector<SPItem*> new_select;
836
804
    GSList *groups = NULL;
837
 
    for (std::vector<SPItem*>::const_iterator item = old_select.begin(); item!=old_select.end(); ++item) {
 
805
    for (std::vector<SPItem*>::const_iterator item = old_select.begin(); item!=old_select.end(); item++) {
838
806
        SPItem *obj = *item;
839
807
        if (dynamic_cast<SPGroup *>(obj)) {
840
808
            groups = g_slist_prepend(groups, obj);
853
821
    // If any of the clones refer to the groups, unlink them and replace them with successors
854
822
    // in the items list.
855
823
    GSList *clones_to_unlink = NULL;
856
 
    for (std::vector<SPItem*>::const_iterator item = items.begin(); item != items.end(); ++item) {
 
824
    for (std::vector<SPItem*>::const_iterator item = items.begin(); item != items.end(); item++) {
857
825
        SPUse *use = dynamic_cast<SPUse *>(*item);
858
826
 
859
827
        SPItem *original = use;
879
847
    g_slist_free(clones_to_unlink);
880
848
 
881
849
    // do the actual work
882
 
    for (std::vector<SPItem*>::iterator item = items.begin(); item != items.end(); ++item) {
 
850
    for (std::vector<SPItem*>::iterator item = items.begin(); item != items.end(); item++) {
883
851
        SPItem *obj = *item;
884
852
 
885
853
        // ungroup only the groups marked earlier
886
854
        if (g_slist_find(groups, *item) != NULL) {
887
 
            std::vector<SPItem*> children;
 
855
                std::vector<SPItem*> children;
888
856
            sp_item_group_ungroup(dynamic_cast<SPGroup *>(obj), children, false);
889
857
            // add the items resulting from ungrouping to the selection
890
858
            new_select.insert(new_select.end(),children.begin(),children.end());
905
873
std::vector<SPItem*>
906
874
sp_degroup_list(std::vector<SPItem*> &items)
907
875
{
908
 
    std::vector<SPItem*> out;
 
876
        std::vector<SPItem*> out;
909
877
    bool has_groups = false;
910
 
    for (std::vector<SPItem*>::const_iterator item=items.begin();item!=items.end();++item) {
 
878
    for (std::vector<SPItem*>::const_iterator item=items.begin();item!=items.end();item++) {
911
879
        SPGroup *group = dynamic_cast<SPGroup *>(*item);
912
880
        if (!group) {
913
881
            out.push_back(*item);
914
882
        } else {
915
883
            has_groups = true;
916
884
            std::vector<SPItem*> members = sp_item_group_item_list(group);
917
 
            for (std::vector<SPItem*>::const_iterator member=members.begin();member!=members.end();++member) {
 
885
            for (std::vector<SPItem*>::const_iterator member=members.begin();member!=members.end();member++) {
918
886
                out.push_back(*member);
919
887
            }
920
888
            members.clear();
931
899
 
932
900
/** If items in the list have a common parent, return it, otherwise return NULL */
933
901
static SPGroup *
934
 
sp_item_list_common_parent_group(std::vector<SPItem*> const &items)
 
902
sp_item_list_common_parent_group(std::vector<SPItem*> const items)
935
903
{
936
904
    if (items.empty()) {
937
905
        return NULL;
941
909
    if (!dynamic_cast<SPGroup *>(parent)) {
942
910
        return NULL;
943
911
    }
944
 
    for (std::vector<SPItem*>::const_iterator item=items.begin();item!=items.end();++item) {
945
 
        if((*item)==items[0])continue;
 
912
    for (std::vector<SPItem*>::const_iterator item=items.begin();item!=items.end();item++) {
 
913
        if((*item)==items[0])continue;
946
914
        if ((*item)->parent != parent) {
947
915
            return NULL;
948
916
        }
958
926
    g_assert(!items.empty());
959
927
 
960
928
    Geom::OptRect r;
961
 
    for (std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();++i) {
 
929
    for (std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++) {
962
930
        r.unionWith((*i)->desktopVisualBounds());
963
931
    }
964
932
    return r;
977
945
bool sp_item_repr_compare_position_bool(SPObject const *first, SPObject const *second)
978
946
{
979
947
    return sp_repr_compare_position(((SPItem*)first)->getRepr(),
980
 
            ((SPItem*)second)->getRepr())<0;
 
948
                ((SPItem*)second)->getRepr())<0;
981
949
}
982
950
 
983
951
void
1006
974
 
1007
975
    // Iterate over all objects in the selection (starting from top).
1008
976
    if (selected) {
1009
 
        for (std::vector<SPItem*>::const_iterator item=rev.begin();item!=rev.end();++item) {
 
977
        for (std::vector<SPItem*>::const_iterator item=rev.begin();item!=rev.end();item++) {
1010
978
            SPObject *child = *item;
1011
979
            // for each selected object, find the next sibling
1012
980
            for (SPObject *newref = child->next; newref; newref = newref->next) {
1051
1019
    std::vector<Inkscape::XML::Node*> rl(selection->reprList());
1052
1020
    sort(rl.begin(),rl.end(),sp_repr_compare_position_bool);
1053
1021
 
1054
 
    for (std::vector<Inkscape::XML::Node*>::const_iterator l=rl.begin(); l!=rl.end();++l) {
 
1022
    for (std::vector<Inkscape::XML::Node*>::const_iterator l=rl.begin(); l!=rl.end();l++) {
1055
1023
        Inkscape::XML::Node *repr =(*l);
1056
1024
        repr->setPosition(-1);
1057
1025
    }
1085
1053
 
1086
1054
    // Iterate over all objects in the selection (starting from top).
1087
1055
    if (selected) {
1088
 
        for (std::vector<SPItem*>::const_reverse_iterator item=rev.rbegin();item!=rev.rend();++item) {
 
1056
        for (std::vector<SPItem*>::const_reverse_iterator item=rev.rbegin();item!=rev.rend();item++) {
1089
1057
            SPObject *child = *item;
1090
1058
            // for each selected object, find the prev sibling
1091
1059
            for (SPObject *newref = prev_sibling(child); newref; newref = prev_sibling(newref)) {
1135
1103
    std::vector<Inkscape::XML::Node*> rl(selection->reprList());
1136
1104
    sort(rl.begin(),rl.end(),sp_repr_compare_position_bool);
1137
1105
 
1138
 
    for (std::vector<Inkscape::XML::Node*>::const_reverse_iterator l=rl.rbegin();l!=rl.rend();++l) {
 
1106
    for (std::vector<Inkscape::XML::Node*>::const_reverse_iterator l=rl.rbegin();l!=rl.rend();l++) {
1139
1107
        gint minpos;
1140
1108
        SPObject *pp, *pc;
1141
1109
        Inkscape::XML::Node *repr = (*l);
1158
1126
sp_undo(SPDesktop *desktop, SPDocument *)
1159
1127
{
1160
1128
    // No re/undo while dragging, too dangerous.
1161
 
    if(desktop->getCanvas()->_is_dragging) return;
 
1129
    if(desktop->getCanvas()->is_dragging) return;
1162
1130
 
1163
1131
    if (!DocumentUndo::undo(desktop->getDocument())) {
1164
1132
        desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing to undo."));
1169
1137
sp_redo(SPDesktop *desktop, SPDocument *)
1170
1138
{
1171
1139
    // No re/undo while dragging, too dangerous.
1172
 
    if(desktop->getCanvas()->_is_dragging) return;
 
1140
    if(desktop->getCanvas()->is_dragging) return;
1173
1141
 
1174
1142
    if (!DocumentUndo::redo(desktop->getDocument())) {
1175
1143
        desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing to redo."));
1288
1256
        return;
1289
1257
    }
1290
1258
    std::vector<SPItem*> list=selection->itemList();
1291
 
    for ( std::vector<SPItem*>::const_iterator itemlist=list.begin();itemlist!=list.end();++itemlist) {
 
1259
    for ( std::vector<SPItem*>::const_iterator itemlist=list.begin();itemlist!=list.end();itemlist++) {
1292
1260
        SPItem *item = *itemlist;
1293
1261
 
1294
1262
        sp_selection_remove_livepatheffect_impl(item);
1345
1313
 */
1346
1314
void sp_selection_change_layer_maintain_clones(std::vector<SPItem*> const &items,SPObject *where)
1347
1315
{
1348
 
    for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); ++i) {
 
1316
    for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); i++) {
1349
1317
        SPItem *item = *i;
1350
1318
        if (item) {
1351
1319
            SPItem *oldparent = dynamic_cast<SPItem *>(item->parent);
1373
1341
    bool no_more = false; // Set to true, if no more layers above
1374
1342
    SPObject *next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer());
1375
1343
    if (next) {
1376
 
        selection->clear();
1377
1344
        sp_selection_change_layer_maintain_clones(items,next);
1378
1345
        std::vector<Inkscape::XML::Node*> temp_clip;
1379
1346
        sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc());
1417
1384
    bool no_more = false; // Set to true, if no more layers below
1418
1385
    SPObject *next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer());
1419
1386
    if (next) {
1420
 
        selection->clear();
1421
1387
        sp_selection_change_layer_maintain_clones(items,next);
1422
1388
        std::vector<Inkscape::XML::Node*> temp_clip;
1423
1389
        sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs
1458
1424
    std::vector<SPItem*> items(selection->itemList());
1459
1425
 
1460
1426
    if (moveto) {
1461
 
        selection->clear();
1462
1427
        sp_selection_change_layer_maintain_clones(items,moveto);
1463
1428
        std::vector<Inkscape::XML::Node*> temp_clip;
1464
1429
        sp_selection_copy_impl(items, temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs
1507
1472
{
1508
1473
    bool clone_with_original = false;
1509
1474
    std::vector<SPItem*> items = selection->itemList();
1510
 
    for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;++l) {
 
1475
    for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;l++) {
1511
1476
        SPItem *item = *l;
1512
1477
        if (item) {
1513
1478
            clone_with_original |= selection_contains_original(item, selection);
1552
1517
        persp3d_apply_affine_transformation(transf_persp, affine);
1553
1518
    }
1554
1519
    std::vector<SPItem*> items = selection->itemList();
1555
 
    for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;++l) {
 
1520
    for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;l++) {
1556
1521
        SPItem *item = *l;
1557
1522
 
1558
1523
        if( dynamic_cast<SPRoot *>(item) ) {
1723
1688
    Inkscape::Selection *selection = desktop->getSelection();
1724
1689
 
1725
1690
    std::vector<Inkscape::XML::Node*> items = selection->reprList();
1726
 
    for (std::vector<Inkscape::XML::Node*>::const_iterator l=items.begin();l!=items.end() ;++l) {
 
1691
    for (std::vector<Inkscape::XML::Node*>::const_iterator l=items.begin();l!=items.end() ;l++) {
1727
1692
        (*l)->setAttribute("transform", NULL, false);
1728
1693
    }
1729
1694
 
1824
1789
 
1825
1790
    std::vector<SPItem*> items = selection->itemList();
1826
1791
    Geom::Rotate const rot_90(Geom::Point(0, ccw ? 1 : -1)); // pos. or neg. rotation, depending on the value of ccw
1827
 
    for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;++l) {
 
1792
    for (std::vector<SPItem*>::const_iterator l=items.begin();l!=items.end() ;l++) {
1828
1793
        SPItem *item = *l;
1829
1794
        if (item) {
1830
1795
            sp_item_rotate_rel(item, rot_90);
1889
1854
    std::vector<SPItem*> items = selection->itemList();
1890
1855
 
1891
1856
    std::vector<SPItem*> tmp;
1892
 
    for (std::vector<SPItem*>::const_iterator iter=all_list.begin();iter!=all_list.end();++iter) {
 
1857
    for (std::vector<SPItem*>::const_iterator iter=all_list.begin();iter!=all_list.end();iter++) {
1893
1858
        if(!SP_IS_GROUP(*iter)){
1894
1859
            tmp.push_back(*iter);
1895
1860
        }
1896
1861
    }
1897
1862
    all_list=tmp;
1898
1863
 
1899
 
    for (std::vector<SPItem*>::const_iterator sel_iter=items.begin();sel_iter!=items.end();++sel_iter) {
 
1864
    for (std::vector<SPItem*>::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) {
1900
1865
        SPItem *sel = *sel_iter;
1901
1866
        std::vector<SPItem*> matches = all_list;
1902
1867
        if (fill && stroke && style) {
1944
1909
    Inkscape::Selection *selection = desktop->getSelection();
1945
1910
 
1946
1911
    std::vector<SPItem*> items=selection->itemList();
1947
 
    for (std::vector<SPItem*>::const_iterator sel_iter=items.begin();sel_iter!=items.end();++sel_iter) {
 
1912
    for (std::vector<SPItem*>::const_iterator sel_iter=items.begin();sel_iter!=items.end();sel_iter++) {
1948
1913
        SPItem *sel = *sel_iter;
1949
1914
        if (sel) {
1950
1915
            matches = sp_get_same_object_type(sel, matches);
1971
1936
 
1972
1937
    SPIPaint *sel_paint = (type == SP_FILL_COLOR) ? &(sel->style->fill) : &(sel->style->stroke);
1973
1938
 
1974
 
    for (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();++i) {
 
1939
    for (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) {
1975
1940
        SPItem *iter = *i;
1976
1941
        if (iter) {
1977
1942
            SPIPaint *iter_paint = (type == SP_FILL_COLOR) ? &(iter->style->fill) : &(iter->style->stroke);
1998
1963
                    }
1999
1964
 
2000
1965
                } else if (dynamic_cast<SPPattern *>(sel_server) && dynamic_cast<SPPattern *>(iter_server)) {
2001
 
                    SPPattern *sel_pat = dynamic_cast<SPPattern *>(sel_server)->rootPattern();
2002
 
                    SPPattern *iter_pat = dynamic_cast<SPPattern *>(iter_server)->rootPattern();
 
1966
                    SPPattern *sel_pat = pattern_getroot(dynamic_cast<SPPattern *>(sel_server));
 
1967
                    SPPattern *iter_pat = pattern_getroot(dynamic_cast<SPPattern *>(iter_server));
2003
1968
                    if (sel_pat == iter_pat) {
2004
1969
                        match = true;
2005
1970
                    }
2066
2031
{
2067
2032
    std::vector<SPItem*> matches;
2068
2033
 
2069
 
    for (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();++i) {
 
2034
    for (std::vector<SPItem*>::const_reverse_iterator i=src.rbegin();i!=src.rend();i++) {
2070
2035
        SPItem *item = *i;
2071
2036
        if (item && item_type_match(sel, item) && !item->cloned) {
2072
2037
            matches.push_back(item);
2107
2072
        objects_query_strokewidth (objects, sel_style_for_width);
2108
2073
    }
2109
2074
    bool match_g;
2110
 
    for (std::vector<SPItem*>::const_iterator i=src.begin();i!=src.end();++i) {
 
2075
    for (std::vector<SPItem*>::const_iterator i=src.begin();i!=src.end();i++) {
2111
2076
        SPItem *iter = *i;
2112
2077
        if (iter) {
2113
2078
            match_g=true;
2147
2112
                    }
2148
2113
                }
2149
2114
            }
2150
 
            match_g = match_g && match;
 
2115
                        match_g = match_g && match;
2151
2116
            if (match_g) {
2152
2117
                while (iter->cloned) iter=dynamic_cast<SPItem *>(iter->parent);
2153
2118
                matches.insert(matches.begin(),iter);
2406
2371
 
2407
2372
 
2408
2373
template <typename D>
2409
 
SPItem *next_item_from_list(SPDesktop *desktop, std::vector<SPItem*> const &items,
 
2374
SPItem *next_item_from_list(SPDesktop *desktop, std::vector<SPItem*> const items,
2410
2375
                            SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive)
2411
2376
{
2412
2377
    SPObject *current=root;
2413
 
    for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();++i) {
 
2378
    for(std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();i++) {
2414
2379
        SPItem *item = *i;
2415
2380
        if ( root->isAncestorOf(item) &&
2416
2381
             ( !only_in_viewport || desktop->isWithinViewport(item) ) )
2612
2577
 
2613
2578
    std::vector<Inkscape::XML::Node*> newsel;
2614
2579
 
2615
 
    for(std::vector<Inkscape::XML::Node*>::const_iterator i=reprs.begin();i!=reprs.end();++i){
2616
 
        Inkscape::XML::Node *sel_repr = *i;
 
2580
    for(std::vector<Inkscape::XML::Node*>::const_reverse_iterator i=reprs.rbegin();i!=reprs.rend();i++){
 
2581
        Inkscape::XML::Node *sel_repr = *i;
2617
2582
        Inkscape::XML::Node *parent = sel_repr->parent();
2618
2583
 
2619
2584
        Inkscape::XML::Node *clone = xml_doc->createElement("svg:use");
2663
2628
    // Get a copy of current selection.
2664
2629
    bool relinked = false;
2665
2630
    std::vector<SPItem*> items=selection->itemList();
2666
 
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
 
2631
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
2667
2632
        SPItem *item = *i;
2668
2633
 
2669
2634
        if (dynamic_cast<SPUse *>(item)) {
2701
2666
    std::vector<SPItem*> new_select;
2702
2667
    bool unlinked = false;
2703
2668
    std::vector<SPItem*> items=selection->itemList();
2704
 
    for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){
 
2669
    for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){
2705
2670
        SPItem *item = *i;
2706
2671
 
2707
2672
        if (dynamic_cast<SPText *>(item)) {
2866
2831
    Inkscape::SVGOStringStream os;
2867
2832
    SPObject * firstItem = NULL;
2868
2833
    std::vector<SPItem*> items=selection->itemList();
2869
 
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
 
2834
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
2870
2835
        if (SP_IS_SHAPE(*i) || SP_IS_TEXT(*i)) {
2871
2836
            if (firstItem) {
2872
2837
                os << "|";
2969
2934
 
2970
2935
    // Create a list of duplicates, to be pasted inside marker element.
2971
2936
    std::vector<Inkscape::XML::Node*> repr_copies;
2972
 
    for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){
 
2937
    for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){
2973
2938
        Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc);
2974
2939
        repr_copies.push_back(dup);
2975
2940
    }
2979
2944
    if (apply) {
2980
2945
        // Delete objects so that their clones don't get alerted;
2981
2946
        // the objects will be restored inside the marker element.
2982
 
        for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
 
2947
        for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
2983
2948
            SPObject *item = *i;
2984
2949
            item->deleteObject(false);
2985
2950
        }
3008
2973
    SPGroup *group = dynamic_cast<SPGroup *>(item);
3009
2974
    if (group && !dynamic_cast<SPBox3D *>(item) && !wholegroups) {
3010
2975
        std::vector<SPItem*> items=sp_item_group_item_list(group);
3011
 
        for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
 
2976
        for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
3012
2977
            sp_selection_to_guides_recursive(*i, wholegroups);
3013
2978
        }
3014
2979
    } else {
3039
3004
    // and its entry in the selection list is invalid (crash).
3040
3005
    // Therefore: first convert all, then delete all.
3041
3006
 
3042
 
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
 
3007
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
3043
3008
        sp_selection_to_guides_recursive(*i, wholegroups);
3044
3009
    }
3045
3010
 
3091
3056
    doc->ensureUpToDate();
3092
3057
 
3093
3058
    std::vector<SPObject*> items(selection->list());
3094
 
    sort(items.begin(),items.end(),sp_object_compare_position_bool);
3095
3059
 
3096
3060
    // Keep track of parent, this is where <use> will be inserted.
3097
3061
    Inkscape::XML::Node *the_first_repr = items[0]->getRepr();
3141
3105
 
3142
3106
        symbol_repr->setAttribute("style",  the_group->getAttribute("style"));
3143
3107
        symbol_repr->setAttribute("class",  the_group->getAttribute("class"));
3144
 
        Glib::ustring id = the_group->getAttribute("id");
3145
 
        the_group->setAttribute("id", id + "_transform");
3146
 
        symbol_repr->setAttribute("id", id);
 
3108
        symbol_repr->setAttribute("id",     the_group->getAttribute("id")   );
3147
3109
 
3148
3110
        // This should eventually be replaced by 'refX' and 'refY' once SVG WG approves it.
3149
3111
        // It is done here for round-tripping
3153
3115
                                  the_group->getAttribute("inkscape:transform-center-y"));
3154
3116
 
3155
3117
        the_group->setAttribute("style", NULL);
 
3118
        Glib::ustring id = symbol_repr->attribute("id");
 
3119
        id += "_transform";
 
3120
        the_group->setAttribute("id", id);
3156
3121
 
3157
3122
    }
3158
3123
 
3159
3124
    // Move selected items to new <symbol>
3160
 
    for (std::vector<SPObject*>::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){
 
3125
    for (std::vector<SPObject*>::const_iterator i=items.begin();i!=items.end();i++){
3161
3126
      Inkscape::XML::Node *repr = (*i)->getRepr();
3162
3127
      repr->parent()->removeChild(repr);
3163
3128
      symbol_repr->addChild(repr,NULL);
3241
3206
        }
3242
3207
    }
3243
3208
        
3244
 
    for (std::vector<SPObject*>::const_reverse_iterator i=children.rbegin();i!=children.rend();++i){
 
3209
    for (std::vector<SPObject*>::const_reverse_iterator i=children.rbegin();i!=children.rend();i++){
3245
3210
        Inkscape::XML::Node *repr = (*i)->getRepr();
3246
3211
        repr->parent()->removeChild(repr);
3247
3212
        group->addChild(repr,NULL);
3325
3290
 
3326
3291
    // create a list of duplicates
3327
3292
    std::vector<Inkscape::XML::Node*> repr_copies;
3328
 
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
 
3293
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
3329
3294
        Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc);
3330
3295
        repr_copies.push_back(dup);
3331
3296
    }
3334
3299
 
3335
3300
    if (apply) {
3336
3301
        // delete objects so that their clones don't get alerted; this object will be restored shortly
3337
 
        for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
 
3302
        for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
3338
3303
            SPObject *item = *i;
3339
3304
            item->deleteObject(false);
3340
3305
        }
3347
3312
    int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
3348
3313
    prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED);
3349
3314
 
3350
 
    gchar const *pat_id = SPPattern::produce(repr_copies, bbox, doc,
 
3315
    gchar const *pat_id = pattern_tile(repr_copies, bbox, doc,
3351
3316
                                       ( Geom::Affine(Geom::Translate(desktop->dt2doc(Geom::Point(r->min()[Geom::X],
3352
3317
                                                                                            r->max()[Geom::Y]))))
3353
3318
                                         * parent_transform.inverse() ),
3408
3373
    bool did = false;
3409
3374
 
3410
3375
    std::vector<SPItem*> items(selection->itemList());
3411
 
    for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();++i){
 
3376
    for (std::vector<SPItem*>::const_reverse_iterator i=items.rbegin();i!=items.rend();i++){
3412
3377
        SPItem *item = *i;
3413
3378
 
3414
3379
        SPStyle *style = item->style;
3425
3390
 
3426
3391
        did = true;
3427
3392
 
3428
 
        SPPattern *pattern = basePat->rootPattern();
 
3393
        SPPattern *pattern = pattern_getroot(basePat);
3429
3394
 
3430
 
        Geom::Affine pat_transform = basePat->getTransform();
 
3395
        Geom::Affine pat_transform = pattern_patternTransform(basePat);
3431
3396
        pat_transform *= item->transform;
3432
3397
 
3433
3398
        for (SPObject *child = pattern->firstChild() ; child != NULL; child = child->next ) {
3477
3442
    bool xdpi_search = TRUE;
3478
3443
    bool ydpi_search = TRUE;
3479
3444
 
3480
 
    for (std::vector<Inkscape::XML::Node*>::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();++i){
 
3445
    for (std::vector<Inkscape::XML::Node*>::const_iterator i=reprlst.begin();filename_search&&xdpi_search&&ydpi_search&&i!=reprlst.end();i++){
3481
3446
        gchar const *dpi_string;
3482
3447
        Inkscape::XML::Node *repr = *i;
3483
3448
 
3528
3493
        *xdpi = atof(dpi_string);
3529
3494
    }
3530
3495
 
 
3496
    dpi_string = NULL;
3531
3497
    dpi_string = repr->attribute("inkscape:export-ydpi");
3532
3498
    if (dpi_string != NULL) {
3533
3499
        *ydpi = atof(dpi_string);
3777
3743
    Inkscape::XML::Node *inner = xml_doc->createElement("svg:g");
3778
3744
    inner->setAttribute("inkscape:label", "Clip");
3779
3745
    
3780
 
    for(std::vector<Inkscape::XML::Node*>::const_iterator i=p.begin();i!=p.end();++i){
3781
 
        Inkscape::XML::Node *current = *i;
 
3746
    for(std::vector<Inkscape::XML::Node*>::const_iterator i=p.begin();i!=p.end();i++){
 
3747
        Inkscape::XML::Node *current = *i;
3782
3748
 
3783
3749
        if (current->parent() == topmost_parent) {
3784
3750
            Inkscape::XML::Node *spnew = current->duplicate(xml_doc);
3913
3879
        apply_to_items.push_back(SP_ITEM(desktop->currentLayer()));
3914
3880
    }
3915
3881
 
3916
 
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i) {
 
3882
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) {
3917
3883
        if((!topmost && !apply_to_layer && *i == items.front())
3918
3884
                || (topmost && !apply_to_layer && *i == items.back())
3919
 
                || apply_to_layer){
 
3885
                        || apply_to_layer){
3920
3886
 
3921
 
            Geom::Affine oldtr=(*i)->transform;
 
3887
                Geom::Affine oldtr=(*i)->transform;
3922
3888
            (*i)->doWriteTransform((*i)->getRepr(), (*i)->i2doc_affine());
3923
3889
            Inkscape::XML::Node *dup = (*i)->getRepr()->duplicate(xml_doc);
3924
3890
            (*i)->doWriteTransform((*i)->getRepr(), oldtr);
3930
3896
            else {
3931
3897
                items_to_select.push_back(*i);
3932
3898
            }
3933
 
            continue;
 
3899
                continue;
3934
3900
        }else{
3935
3901
            apply_to_items.push_back(*i);
3936
3902
            items_to_select.push_back(*i);
3948
3914
        group->setAttribute("inkscape:groupmode", "maskhelper");
3949
3915
 
3950
3916
        std::vector<Inkscape::XML::Node*> reprs_to_group;
3951
 
        for (std::vector<SPItem*>::const_iterator i = apply_to_items.begin(); i != apply_to_items.end(); ++i) {
 
3917
        for (std::vector<SPItem*>::const_iterator i = apply_to_items.begin(); i != apply_to_items.end(); i++) {
3952
3918
            reprs_to_group.push_back(static_cast<SPObject*>(*i)->getRepr());
3953
3919
        }
3954
3920
        items_to_select.clear();
3969
3935
 
3970
3936
 
3971
3937
    gchar const *attributeName = apply_clip_path ? "clip-path" : "mask";
3972
 
    for (std::vector<SPItem*>::const_reverse_iterator i = apply_to_items.rbegin(); i != apply_to_items.rend(); ++i) {
 
3938
    for (std::vector<SPItem*>::const_reverse_iterator i = apply_to_items.rbegin(); i != apply_to_items.rend(); i++) {
3973
3939
        SPItem *item = reinterpret_cast<SPItem *>(*i);
3974
3940
        // inverted object transform should be applied to a mask object,
3975
3941
        // as mask is calculated in user space (after applying transform)
3976
3942
        std::vector<Inkscape::XML::Node*> mask_items_dup;
3977
 
        for(std::vector<Inkscape::XML::Node*>::const_iterator it=mask_items.begin();it!=mask_items.end();++it)
3978
 
            mask_items_dup.push_back((*it)->duplicate(xml_doc));
 
3943
        for(std::vector<Inkscape::XML::Node*>::const_iterator it=mask_items.begin();it!=mask_items.end();it++)
 
3944
                mask_items_dup.push_back((*it)->duplicate(xml_doc));
3979
3945
        Inkscape::XML::Node *current = SP_OBJECT(*i)->getRepr();
3980
3946
        // Node to apply mask to
3981
3947
        Inkscape::XML::Node *apply_mask_to = current;
4014
3980
 
4015
3981
    }
4016
3982
 
4017
 
    for (std::vector<SPItem*>::const_iterator i = items_to_delete.begin(); i != items_to_delete.end(); ++i) {
 
3983
    for (std::vector<SPItem*>::const_iterator i = items_to_delete.begin(); i != items_to_delete.end(); i++) {
4018
3984
        SPObject *item = reinterpret_cast<SPObject*>(*i);
4019
3985
        item->deleteObject(false);
4020
3986
        items_to_select.erase(remove(items_to_select.begin(), items_to_select.end(), item), items_to_select.end());
4061
4027
 
4062
4028
    // SPObject* refers to a group containing the clipped path or mask itself,
4063
4029
    // whereas SPItem* refers to the item being clipped or masked
4064
 
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
 
4030
    for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++){
4065
4031
        if (remove_original) {
4066
4032
            // remember referenced mask/clippath, so orphaned masks can be moved back to document
4067
4033
            SPItem *item = *i;