162
162
_emitChanged(persist_selection_context);
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()) {
175
165
void Selection::add_3D_boxes_recursively(SPObject *obj) {
176
166
std::list<SPBox3D *> boxes = box3d_extract_boxes(obj);
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);
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");
230
if ((*p).second > 1) {
237
211
void Selection::remove_3D_boxes_recursively(SPObject *obj) {
238
212
std::list<SPBox3D *> boxes = box3d_extract_boxes(obj);
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");
248
221
_3dboxes.erase(b);
249
remove_box_perspective(box);
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())
353
std::list<SPBox3D *> const Selection::box3DList() {
327
std::list<SPBox3D *> const Selection::box3DList(Persp3D *persp) {
328
std::list<SPBox3D *> boxes;
331
for (std::list<SPBox3D *>::iterator i = _3dboxes.begin(); i != _3dboxes.end(); ++i) {
333
if (persp == box3d_get_perspective(box))
334
boxes.push_back(box);
357
342
SPObject *Selection::single() {
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.
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();
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
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);
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));
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();
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
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);
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
470
cvh.add((*i).getPoint());
482
473
Geom::OptRect rHull = cvh.bounds();
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));