~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/sp-shape.cpp

  • Committer: Diederik van Lierop
  • Date: 2010-01-09 21:14:38 UTC
  • Revision ID: diederik_van_lierop_mail_at-sign_diedenrezi_dot_nl-20100109211438-ciqi6nxmir7zvv6x
Refactoring the snapping API (making it easier to maintain and understand for the devs)

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
void sp_shape_print (SPItem * item, SPPrintContext * ctx);
69
69
static NRArenaItem *sp_shape_show (SPItem *item, NRArena *arena, unsigned int key, unsigned int flags);
70
70
static void sp_shape_hide (SPItem *item, unsigned int key);
71
 
static void sp_shape_snappoints (SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs);
 
71
static void sp_shape_snappoints (SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs);
72
72
 
73
73
static void sp_shape_update_marker_view (SPShape *shape, NRArenaItem *ai);
74
74
 
1149
1149
/**
1150
1150
 * Return all nodes in a path that are to be considered for snapping
1151
1151
 */
1152
 
static void sp_shape_snappoints(SPItem const *item, bool const target, SnapPointsWithType &p, Inkscape::SnapPreferences const *snapprefs)
 
1152
static void sp_shape_snappoints(SPItem const *item, std::vector<Inkscape::SnapCandidatePoint> &p, Inkscape::SnapPreferences const *snapprefs)
1153
1153
{
1154
1154
    g_assert(item != NULL);
1155
1155
    g_assert(SP_IS_SHAPE(item));
1161
1161
 
1162
1162
    // Help enforcing strict snapping, i.e. only return nodes when we're snapping nodes to nodes or a guide to nodes
1163
1163
    if (!(snapprefs->getSnapModeNode() || snapprefs->getSnapModeGuide())) {
1164
 
        return;
 
1164
        return;
1165
1165
    }
1166
1166
 
1167
1167
    Geom::PathVector const &pathv = shape->curve->get_pathvector();
1170
1170
 
1171
1171
    Geom::Matrix const i2d (sp_item_i2d_affine (item));
1172
1172
 
1173
 
    int type;
1174
 
 
1175
 
        if (snapprefs->getSnapObjectMidpoints()) {
1176
 
                Geom::OptRect bbox = item->getBounds(sp_item_i2d_affine(item));
1177
 
                if (bbox) {
1178
 
                        type = target ? int(Inkscape::SNAPTARGET_OBJECT_MIDPOINT) : int(Inkscape::SNAPSOURCE_OBJECT_MIDPOINT);
1179
 
                        p.push_back(std::make_pair(bbox->midpoint(), type));
1180
 
                }
1181
 
        }
 
1173
    if (snapprefs->getSnapObjectMidpoints()) {
 
1174
        Geom::OptRect bbox = item->getBounds(sp_item_i2d_affine(item));
 
1175
        if (bbox) {
 
1176
            p.push_back(Inkscape::SnapCandidatePoint(bbox->midpoint(), Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT));
 
1177
        }
 
1178
    }
1182
1179
 
1183
1180
    for(Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) {
1184
1181
        if (snapprefs->getSnapToItemNode()) {
1185
 
                type = target ? int(Inkscape::SNAPTARGET_NODE_CUSP) : int(Inkscape::SNAPSOURCE_NODE_CUSP);
1186
 
                p.push_back(std::make_pair(path_it->initialPoint() * i2d, type));
 
1182
            p.push_back(Inkscape::SnapCandidatePoint(path_it->initialPoint() * i2d, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP));
1187
1183
        }
1188
1184
 
1189
1185
        Geom::Path::const_iterator curve_it1 = path_it->begin();      // incoming curve
1202
1198
            bool c2 = snapprefs->getSnapSmoothNodes() && (nodetype == Geom::NODE_SMOOTH || nodetype == Geom::NODE_SYMM);
1203
1199
 
1204
1200
            if (c1 || c2) {
1205
 
                type = target ? int(Inkscape::SNAPTARGET_NODE_CUSP) : int(Inkscape::SNAPSOURCE_NODE_CUSP);
1206
 
                                p.push_back(std::make_pair(curve_it1->finalPoint() * i2d, type));
 
1201
                p.push_back(Inkscape::SnapCandidatePoint(curve_it1->finalPoint() * i2d, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP));
1207
1202
            }
1208
1203
 
1209
 
                        // Consider midpoints of line segments for snapping
1210
 
                        if (snapprefs->getSnapLineMidpoints()) { // only do this when we're snapping nodes (enforce strict snapping)
1211
 
                                if (Geom::LineSegment const* line_segment = dynamic_cast<Geom::LineSegment const*>(&(*curve_it1))) {
1212
 
                                        type = target ? int(Inkscape::SNAPTARGET_LINE_MIDPOINT) : int(Inkscape::SNAPSOURCE_LINE_MIDPOINT);
1213
 
                                        p.push_back(std::make_pair(Geom::middle_point(*line_segment) * i2d, type));
1214
 
                                }
1215
 
                        }
 
1204
            // Consider midpoints of line segments for snapping
 
1205
            if (snapprefs->getSnapLineMidpoints()) { // only do this when we're snapping nodes (enforce strict snapping)
 
1206
                if (Geom::LineSegment const* line_segment = dynamic_cast<Geom::LineSegment const*>(&(*curve_it1))) {
 
1207
                    p.push_back(Inkscape::SnapCandidatePoint(Geom::middle_point(*line_segment) * i2d, Inkscape::SNAPSOURCE_LINE_MIDPOINT, Inkscape::SNAPTARGET_LINE_MIDPOINT));
 
1208
                }
 
1209
            }
1216
1210
 
1217
1211
            ++curve_it1;
1218
1212
            ++curve_it2;
1226
1220
            if (cs.size() > 0) { // There might be multiple intersections...
1227
1221
                for (Geom::Crossings::const_iterator i = cs.begin(); i != cs.end(); i++) {
1228
1222
                    Geom::Point p_ix = (*path_it).pointAt((*i).ta);
1229
 
                    type = target ? int(Inkscape::SNAPTARGET_PATH_INTERSECTION) : int(Inkscape::SNAPSOURCE_PATH_INTERSECTION);
1230
 
                    p.push_back(std::make_pair(p_ix * i2d, type));
 
1223
                    p.push_back(Inkscape::SnapCandidatePoint(p_ix * i2d, Inkscape::SNAPSOURCE_PATH_INTERSECTION, Inkscape::SNAPTARGET_PATH_INTERSECTION));
1231
1224
                }
1232
1225
            }
1233
1226
        }