diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2012-01-17 18:54:58 +0000 |
|---|---|---|
| committer | Johan Engelen <goejendaagh@zonnet.nl> | 2012-01-17 18:54:58 +0000 |
| commit | 9987e96d0f03421344ad50447a877d57058e0df5 (patch) | |
| tree | 3da0d794c798977a50770ef8f914c17aa780b3b9 /src | |
| parent | proper forward decl (diff) | |
| download | inkscape-9987e96d0f03421344ad50447a877d57058e0df5.tar.gz inkscape-9987e96d0f03421344ad50447a877d57058e0df5.zip | |
part 1 of SPPath cleanup for LPE... remove duplicated original_curve in SPPath (SPShape has curve_before_lpe)
(bzr r10895)
Diffstat (limited to 'src')
| -rw-r--r-- | src/connector-context.cpp | 11 | ||||
| -rw-r--r-- | src/path-chemistry.cpp | 2 | ||||
| -rw-r--r-- | src/sp-conn-end-pair.cpp | 4 | ||||
| -rw-r--r-- | src/sp-path.cpp | 87 | ||||
| -rw-r--r-- | src/sp-path.h | 3 | ||||
| -rw-r--r-- | src/sp-shape.h | 4 |
6 files changed, 61 insertions, 50 deletions
diff --git a/src/connector-context.cpp b/src/connector-context.cpp index b2687e540..7ab617094 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -980,7 +980,7 @@ connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion cons Geom::Affine i2d ( (cc->clickeditem)->i2dt_affine() ); Geom::Affine d2i = i2d.inverse(); SPPath *path = SP_PATH(cc->clickeditem); - SPCurve *curve = path->original_curve ? path->original_curve : path->curve; + SPCurve *curve = sp_path_get_curve(path); if (cc->clickedhandle == cc->endpt_handle[0]) { Geom::Point o = cc->endpt_handle[1]->pos; curve->stretch_endpoints(p * d2i, o * d2i); @@ -992,8 +992,7 @@ connector_handle_motion_notify(SPConnectorContext *const cc, GdkEventMotion cons sp_conn_reroute_path_immediate(path); // Copy this to the temporary visible path - cc->red_curve = path->original_curve ? - path->original_curve->copy() : path->curve->copy(); + cc->red_curve = sp_path_get_curve_for_edit(path); cc->red_curve->transform(i2d); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve); @@ -1606,7 +1605,7 @@ endpt_handler(SPKnot */*knot*/, GdkEvent *event, SPConnectorContext *cc) } // Show the red path for dragging. - cc->red_curve = SP_PATH(cc->clickeditem)->original_curve ? SP_PATH(cc->clickeditem)->original_curve->copy() : SP_PATH(cc->clickeditem)->curve->copy(); + cc->red_curve = sp_path_get_curve_for_edit(SP_PATH(cc->clickeditem)); Geom::Affine i2d = (cc->clickeditem)->i2dt_affine(); cc->red_curve->transform(i2d); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve); @@ -1765,7 +1764,7 @@ cc_set_active_conn(SPConnectorContext *cc, SPItem *item) { g_assert( SP_IS_PATH(item) ); - SPCurve *curve = SP_PATH(item)->original_curve ? SP_PATH(item)->original_curve : SP_PATH(item)->curve; + const SPCurve *curve = sp_path_get_curve_reference(SP_PATH(item)); Geom::Affine i2dt = item->i2dt_affine(); if (cc->active_conn == item) @@ -1918,7 +1917,7 @@ static bool cc_item_is_shape(SPItem *item) bool cc_item_is_connector(SPItem *item) { if (SP_IS_PATH(item)) { - bool closed = SP_PATH(item)->original_curve ? SP_PATH(item)->original_curve->is_closed() : SP_PATH(item)->curve->is_closed(); + bool closed = sp_path_get_curve_reference(SP_PATH(item))->is_closed(); if (SP_PATH(item)->connEndPair.isAutoRoutingConn() && !closed) { // To be considered a connector, an object must be a non-closed // path that is marked with a "inkscape:connector-type" attribute. diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 11334c651..b2680acce 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -379,7 +379,7 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec continue; } - if (SP_IS_PATH(item) && !SP_PATH(item)->original_curve) { + if (SP_IS_PATH(item) && !SP_SHAPE(item)->curve_before_lpe) { continue; // already a path, and no path effect } diff --git a/src/sp-conn-end-pair.cpp b/src/sp-conn-end-pair.cpp index 00b9ab0e9..fa01dc2d8 100644 --- a/src/sp-conn-end-pair.cpp +++ b/src/sp-conn-end-pair.cpp @@ -214,7 +214,7 @@ SPConnEndPair::getAttachedItems(SPItem *h2attItem[2]) const { void SPConnEndPair::getEndpoints(Geom::Point endPts[]) const { - SPCurve *curve = _path->original_curve ? _path->original_curve : _path->curve; + SPCurve const *curve = sp_path_get_curve_reference(_path); SPItem *h2attItem[2] = {0}; getAttachedItems(h2attItem); Geom::Affine i2d = _path->i2doc_affine(); @@ -403,7 +403,7 @@ SPConnEndPair::reroutePathFromLibavoid(void) return false; } - SPCurve *curve = _path->original_curve ?_path->original_curve : _path->curve; + SPCurve *curve = sp_path_get_curve(_path); recreateCurve( curve, _connRef, _connCurvature ); diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 49cadc116..2cf09c4a1 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -192,8 +192,6 @@ static void sp_path_init(SPPath *path) { new (&path->connEndPair) SPConnEndPair(path); - - path->original_curve = NULL; } static void @@ -240,10 +238,6 @@ sp_path_release(SPObject *object) path->connEndPair.release(); - if (path->original_curve) { - path->original_curve = path->original_curve->unref(); - } - if (((SPObjectClass *) parent_class)->release) { ((SPObjectClass *) parent_class)->release(object); } @@ -333,9 +327,8 @@ g_message("sp_path_write writes 'd' attribute"); } if (flags & SP_OBJECT_WRITE_EXT) { - SPPath *path = (SPPath *) object; - if ( path->original_curve != NULL ) { - gchar *str = sp_svg_write_path(path->original_curve->get_pathvector()); + if ( shape->curve_before_lpe != NULL ) { + gchar *str = sp_svg_write_path(shape->curve_before_lpe->get_pathvector()); repr->setAttribute("inkscape:original-d", str); g_free(str); } else { @@ -374,19 +367,20 @@ sp_path_update(SPObject *object, SPCtx *ctx, guint flags) static Geom::Affine sp_path_set_transform(SPItem *item, Geom::Affine const &xform) { - SPShape *shape = (SPShape *) item; - SPPath *path = (SPPath *) item; + if (!SP_IS_PATH(item)) { + return Geom::identity(); + } + SPPath *path = SP_PATH(item); - if (!shape->curve) { // 0 nodes, nothing to transform + if (!path->curve) { // 0 nodes, nothing to transform return Geom::identity(); } // Transform the original-d path if this is a valid LPE item, other else the (ordinary) path - if (path->original_curve && SP_IS_LPE_ITEM(item) && - sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(item))) { - path->original_curve->transform(xform); + if (path->curve_before_lpe && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(item))) { + path->curve_before_lpe->transform(xform); } else { - shape->curve->transform(xform); + path->curve->transform(xform); } // Adjust stroke @@ -412,19 +406,17 @@ static void sp_path_update_patheffect(SPLPEItem *lpeitem, bool write) { SPShape * const shape = (SPShape *) lpeitem; - SPPath * const path = (SPPath *) lpeitem; Inkscape::XML::Node *repr = shape->getRepr(); #ifdef PATH_VERBOSE g_message("sp_path_update_patheffect"); #endif - if (path->original_curve && sp_lpe_item_has_path_effect_recursive(lpeitem)) { - SPCurve *curve = path->original_curve->copy(); - /* if a path does not have an lpeitem applied, then reset the curve to the original_curve. + if (shape->curve_before_lpe && sp_lpe_item_has_path_effect_recursive(lpeitem)) { + SPCurve *curve = shape->curve_before_lpe->copy(); + /* if a path has an lpeitem applied, then reset the curve to the curve_before_lpe. * This is very important for LPEs to work properly! (the bbox might be recalculated depending on the curve in shape)*/ shape->setCurveInsync(curve, TRUE); - shape->setCurveBeforeLPE(path->original_curve); bool success = sp_lpe_item_perform_path_effect(SP_LPE_ITEM(shape), curve); if (success && write) { @@ -467,14 +459,14 @@ g_message("sp_path_update_patheffect writes 'd' attribute"); void sp_path_set_original_curve (SPPath *path, SPCurve *curve, unsigned int owner, bool write) { - if (path->original_curve) { - path->original_curve = path->original_curve->unref(); + if (path->curve_before_lpe) { + path->curve_before_lpe = path->curve_before_lpe->unref(); } if (curve) { if (owner) { - path->original_curve = curve->ref(); + path->curve_before_lpe = curve->ref(); } else { - path->original_curve = curve->copy(); + path->curve_before_lpe = curve->copy(); } } sp_lpe_item_update_patheffect(path, true, write); @@ -482,42 +474,63 @@ sp_path_set_original_curve (SPPath *path, SPCurve *curve, unsigned int owner, bo } /** - * Return duplicate of original_curve (if any exists) or NULL if there is no curve + * Return duplicate of curve_before_lpe (if any exists) or NULL if there is no curve */ SPCurve * sp_path_get_original_curve (SPPath *path) { - if (path->original_curve) { - return path->original_curve->copy(); + if (path->curve_before_lpe) { + return path->curve_before_lpe->copy(); } return NULL; } /** - * Return duplicate of edittable curve which is original_curve if it exists or + * Return duplicate of edittable curve which is curve_before_lpe if it exists or * shape->curve if not. */ SPCurve* sp_path_get_curve_for_edit (SPPath *path) { - if (path->original_curve && SP_IS_LPE_ITEM(path) && - sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(path))) { + if (!SP_IS_PATH(path)) { + return NULL; + } + if (path->curve_before_lpe && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(path))) { return sp_path_get_original_curve(path); } else { - return ((SPShape *) path)->getCurve(); + return path->getCurve(); } } /** - * Return a reference to original_curve if it exists or - * shape->curve if not. + * Returns \c curve_before_lpe if it is not NULL and a valid LPE is applied or + * \c curve if not. */ const SPCurve* sp_path_get_curve_reference (SPPath *path) { - if (path->original_curve && SP_IS_LPE_ITEM(path) && - sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(path))) { - return path->original_curve; + if (!SP_IS_PATH(path)) { + return NULL; + } + if (path->curve_before_lpe && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(path))) { + return path->curve_before_lpe; + } else { + return path->curve; + } +} + +/** + * Returns \c curve_before_lpe if it is not NULL and a valid LPE is applied or \c curve if not. + * \todo should only be available to class friends! + */ +SPCurve* +sp_path_get_curve (SPPath *path) +{ + if (!SP_IS_PATH(path)) { + return NULL; + } + if (path->curve_before_lpe && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(path))) { + return path->curve_before_lpe; } else { return path->curve; } diff --git a/src/sp-path.h b/src/sp-path.h index 5cfa34913..3d66794d1 100644 --- a/src/sp-path.h +++ b/src/sp-path.h @@ -23,8 +23,6 @@ struct SPCurve; #define SP_IS_PATH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_PATH)) struct SPPath : public SPShape { - SPCurve *original_curve; - SPConnEndPair connEndPair; }; @@ -39,6 +37,7 @@ void sp_path_set_original_curve (SPPath *path, SPCurve *curve, unsigned int SPCurve* sp_path_get_original_curve (SPPath *path); SPCurve* sp_path_get_curve_for_edit (SPPath *path); const SPCurve* sp_path_get_curve_reference (SPPath *path); +SPCurve* sp_path_get_curve (SPPath *path); // should only be available for friends and not public! #endif // SEEN_SP_PATH_H diff --git a/src/sp-shape.h b/src/sp-shape.h index c5e9588b3..bb7b6cf02 100644 --- a/src/sp-shape.h +++ b/src/sp-shape.h @@ -46,7 +46,7 @@ public: SPObject *marker[SP_MARKER_LOC_QTY]; sigc::connection release_connect [SP_MARKER_LOC_QTY]; sigc::connection modified_connect [SP_MARKER_LOC_QTY]; - + static GType getType (void); void setShape (); SPCurve * getCurve (); @@ -57,7 +57,7 @@ public: int hasMarkers () const; int numberOfMarkers (int type); -protected: +public: // temporarily public, until SPPath is properly classed, etc. SPCurve *curve_before_lpe; private: |
