~ubuntu-branches/ubuntu/precise/inkscape/precise-updates

« back to all changes in this revision

Viewing changes to src/selection.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:
162
162
    _emitChanged(persist_selection_context);
163
163
}
164
164
 
165
 
void Selection::add_box_perspective(SPBox3D *box) {
166
 
    Persp3D *persp = box3d_get_perspective(box);
167
 
    std::map<Persp3D *, unsigned int>::iterator p = _persps.find(persp);
168
 
    if (p != _persps.end()) {
169
 
        (*p).second++;
170
 
    } else {
171
 
        _persps[persp] = 1;
172
 
    }
173
 
}
174
 
 
175
165
void Selection::add_3D_boxes_recursively(SPObject *obj) {
176
166
    std::list<SPBox3D *> boxes = box3d_extract_boxes(obj);
177
167
 
178
168
    for (std::list<SPBox3D *>::iterator i = boxes.begin(); i != boxes.end(); ++i) {
179
169
        SPBox3D *box = *i;
180
 
        box3d_add_to_selection(box);
181
170
        _3dboxes.push_back(box);
182
 
        add_box_perspective(box);
183
171
    }
184
172
}
185
173
 
220
208
    _emitChanged();
221
209
}
222
210
 
223
 
void Selection::remove_box_perspective(SPBox3D *box) {
224
 
    Persp3D *persp = box3d_get_perspective(box);
225
 
    std::map<Persp3D *, unsigned int>::iterator p = _persps.find(persp);
226
 
    if (p == _persps.end()) {
227
 
        g_print ("Warning! Trying to remove unselected perspective from selection!\n");
228
 
        return;
229
 
    }
230
 
    if ((*p).second > 1) {
231
 
        _persps[persp]--;
232
 
    } else {
233
 
        _persps.erase(p);
234
 
    }
235
 
}
236
 
 
237
211
void Selection::remove_3D_boxes_recursively(SPObject *obj) {
238
212
    std::list<SPBox3D *> boxes = box3d_extract_boxes(obj);
239
213
 
240
214
    for (std::list<SPBox3D *>::iterator i = boxes.begin(); i != boxes.end(); ++i) {
241
215
        SPBox3D *box = *i;
242
 
        box3d_remove_from_selection(box);
243
216
        std::list<SPBox3D *>::iterator b = std::find(_3dboxes.begin(), _3dboxes.end(), box);
244
217
        if (b == _3dboxes.end()) {
245
218
            g_print ("Warning! Trying to remove unselected box from selection.\n");
246
219
            return;
247
220
        }
248
221
        _3dboxes.erase(b);
249
 
        remove_box_perspective(box);
250
222
    }
251
223
}
252
224
 
344
316
 
345
317
std::list<Persp3D *> const Selection::perspList() {
346
318
    std::list<Persp3D *> pl;
347
 
    for (std::map<Persp3D *, unsigned int>::iterator p = _persps.begin(); p != _persps.end(); ++p) {
348
 
        pl.push_back((*p).first);
 
319
    for (std::list<SPBox3D *>::iterator i = _3dboxes.begin(); i != _3dboxes.end(); ++i) {
 
320
        Persp3D *persp = box3d_get_perspective(*i);
 
321
        if (std::find(pl.begin(), pl.end(), persp) == pl.end())
 
322
            pl.push_back(persp);
349
323
    }
350
324
    return pl;
351
325
}
352
326
 
353
 
std::list<SPBox3D *> const Selection::box3DList() {
354
 
    return _3dboxes;
 
327
std::list<SPBox3D *> const Selection::box3DList(Persp3D *persp) {
 
328
    std::list<SPBox3D *> boxes;
 
329
    if (persp) {
 
330
        SPBox3D *box;
 
331
        for (std::list<SPBox3D *>::iterator i = _3dboxes.begin(); i != _3dboxes.end(); ++i) {
 
332
            box = *i;
 
333
            if (persp == box3d_get_perspective(box))
 
334
                boxes.push_back(box);
 
335
        }
 
336
    } else {
 
337
        boxes = _3dboxes;
 
338
    }
 
339
    return boxes;
355
340
}
356
341
 
357
342
SPObject *Selection::single() {
439
424
}
440
425
 
441
426
/**
442
 
 * Compute the list of points in the selection that are to be considered for snapping.
 
427
 * Compute the list of points in the selection that are to be considered for snapping from.
443
428
 */
444
 
std::vector<std::pair<Geom::Point, int> > Selection::getSnapPoints(SnapPreferences const *snapprefs) const {
 
429
std::vector<Inkscape::SnapCandidatePoint> Selection::getSnapPoints(SnapPreferences const *snapprefs) const {
445
430
    GSList const *items = const_cast<Selection *>(this)->itemList();
446
431
 
447
432
    SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs
448
433
    snapprefs_dummy.setIncludeItemCenter(false); // locally disable snapping to the item center
449
 
 
450
 
    std::vector<std::pair<Geom::Point, int> > p;
 
434
    snapprefs_dummy.setSnapToItemNode(true); // consider any type of nodes as a snap source
 
435
    snapprefs_dummy.setSnapSmoothNodes(true); // i.e. disregard the smooth / cusp node preference
 
436
    std::vector<Inkscape::SnapCandidatePoint> p;
451
437
    for (GSList const *iter = items; iter != NULL; iter = iter->next) {
452
438
        SPItem *this_item = SP_ITEM(iter->data);
453
 
        sp_item_snappoints(this_item, false, p, &snapprefs_dummy);
 
439
        sp_item_snappoints(this_item, p, &snapprefs_dummy);
454
440
 
455
441
        //Include the transformation origin for snapping
456
442
        //For a selection or group only the overall origin is considered
457
443
        if (snapprefs != NULL && snapprefs->getIncludeItemCenter()) {
458
 
                p.push_back(std::make_pair(this_item->getCenter(), SNAPSOURCE_ROTATION_CENTER));
 
444
            p.push_back(Inkscape::SnapCandidatePoint(this_item->getCenter(), SNAPSOURCE_ROTATION_CENTER));
459
445
        }
460
446
    }
461
447
 
462
448
    return p;
463
449
}
464
 
 
465
 
std::vector<std::pair<Geom::Point, int> > Selection::getSnapPointsConvexHull(SnapPreferences const *snapprefs) const {
 
450
// TODO: both getSnapPoints and getSnapPointsConvexHull are called, subsequently. Can we do this more efficient?
 
451
// Why do we need to include the transformation center in one case and not the other?
 
452
std::vector<Inkscape::SnapCandidatePoint> Selection::getSnapPointsConvexHull(SnapPreferences const *snapprefs) const {
466
453
    GSList const *items = const_cast<Selection *>(this)->itemList();
467
454
 
468
 
    std::vector<std::pair<Geom::Point, int> > p;
 
455
    SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs
 
456
    snapprefs_dummy.setSnapToItemNode(true); // consider any type of nodes as a snap source
 
457
    snapprefs_dummy.setSnapSmoothNodes(true); // i.e. disregard the smooth / cusp node preference
 
458
 
 
459
    std::vector<Inkscape::SnapCandidatePoint> p;
469
460
    for (GSList const *iter = items; iter != NULL; iter = iter->next) {
470
 
                sp_item_snappoints(SP_ITEM(iter->data), false, p, snapprefs);
 
461
        sp_item_snappoints(SP_ITEM(iter->data), p, &snapprefs_dummy);
471
462
    }
472
463
 
473
 
    std::vector<std::pair<Geom::Point, int> > pHull;
 
464
    std::vector<Inkscape::SnapCandidatePoint> pHull;
474
465
    if (!p.empty()) {
475
 
        std::vector<std::pair<Geom::Point, int> >::iterator i;
476
 
        Geom::RectHull cvh((p.front()).first);
 
466
        std::vector<Inkscape::SnapCandidatePoint>::iterator i;
 
467
        Geom::RectHull cvh((p.front()).getPoint());
477
468
        for (i = p.begin(); i != p.end(); i++) {
478
469
            // these are the points we get back
479
 
            cvh.add((*i).first);
 
470
            cvh.add((*i).getPoint());
480
471
        }
481
472
 
482
473
        Geom::OptRect rHull = cvh.bounds();
483
474
        if (rHull) {
484
475
            for ( unsigned i = 0 ; i < 4 ; ++i ) {
485
 
                pHull.push_back(std::make_pair(rHull->corner(i), SNAPSOURCE_CONVEX_HULL_CORNER));
 
476
                pHull.push_back(Inkscape::SnapCandidatePoint(rHull->corner(i), SNAPSOURCE_CONVEX_HULL_CORNER));
486
477
            }
487
478
        }
488
479
    }